0

I am getting content of HTML tag by using outerHTML

var t=$("html")[0].outerHTML;

but I need to remove a specific div from result

<div id="admin_panel">...</div>

here is my jQuery code:

$(function() {
    $('#save').click(function(){
        var t=$("html")[0].outerHTML;
        $.ajax({
            type: "POST",
            url: "save.php",
            data: { code: t },
            cache: false,
            success: function(html){
                alert('Changed saved');
            }
        });
    })
});

How do I remove the div correctly?

mplungjan
  • 169,008
  • 28
  • 173
  • 236

2 Answers2

0

Looks like that:

$(function() {
    $('#save').click(function(){
        var t = $("html")[0].outerHTML;
        var $t = $(t);
        $t.find("#admin_panel").remove();
        t = $t[0].outerHTML;
        $.ajax({
            type: "POST",
            url: "save.php",
            data: { code: t },
            cache: false,
            success: function(html){
                alert('Changed saved');
            }
        });
    })
});
ixpl0
  • 748
  • 5
  • 15
0

Non-destructive:

jQuery: outer html()

var $div = $('<div/>').append($('html').clone()).html();
$div.find("#admin-panel").remove();
var t=$div.html();
Community
  • 1
  • 1
mplungjan
  • 169,008
  • 28
  • 173
  • 236