JQuery - Retrieving all content inside a DIV EXCEPT a specific object

how do i get all the content inside a div? I want to save all the code that exists in the #wrapper DIV on my page. It's simple. But the fact is that ... how to select all EXCEPT for one specific object (image with the "main" class).

You can see how it works here http://www.jsfiddle.net/8A27a/

This is what I still have:

        <div id="wrapper">
            <div class="icon"><img src="http://www.yousendit.com/en_US/theme_default/images/g_logo_trans_110x63.gif"></div>
            <div class="icon"><img src="http://www.yousendit.com/en_US/theme_default/images/g_logo_trans_110x63.gif"></div>   
            <div class="icon"><img src="http://www.yousendit.com/en_US/theme_default/images/g_logo_trans_110x63.gif"></div>  
            <img class="main" src="http://afteramerica.files.wordpress.com/2010/01/061221225103_abraham_lincoln_lg1.jpg">
        </div>

        <input type="button" value="save" class="save">

    <script>
$(document).ready(function() { 
            $('.save').live('click', function() {
                var content = $('#wrapper').html();
                alert(content);
             });
});
</script>
+3
source share
3 answers

The only reliable way I can come up with is to clone the DIV, remove the IMG tag, and get the resulting HTML:

var e = $('#wrapper').clone();
$('img.main', e).remove();
alert(e.html());

, DIV .

+8

$('.save').live('click', function() {
    var content = $('#wrapper > *').not('img.main').clone();
    content = $('<div></div>').append(content);
    content = content.html();
    alert(content);
 });

[edit] , OP.

+2

Check out the selector .not: http://api.jquery.com/not-selector/

+1
source

Source: https://habr.com/ru/post/1774213/


All Articles