2016-12-02 71 views
-1

我用outerHTMLHTML內容的outerHTML內容,並刪除一個DIV

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

越來越HTML標籤的內容,但我需要從結果中刪除特定的div

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

這裏是我的jQuery代碼:

$(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'); 
      } 
     }); 
    }) 
}); 

如何正確刪除div?

回答

0

貌似是:

$(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'); 
      } 
     }); 
    }) 
}); 
+0

謝謝,但我需要一個重新的div! – user2068294

+0

哎呀!修復了答案。試試這個 – ixpl0

+0

哦,我看到你已經找到了方式:D – ixpl0

0

無損:

jQuery: outer html()

var $div = $('<div/>').append($('html').clone()).html(); 
$div.find("#admin-panel").remove(); 
var t=$div.html();