JQuery get live HTML DOM change

Say, for example, I store the HTML content of the body tag in a jQuery variable. In this way,

var current_html = $("body").html();

Then I add some DIV and make other dynamic changes. Even if I update the current_html variable after every DOM change for some reason, it only ever displays the original DOM content when the document loads and does not contain any added elements .... although I update the current_html variable.

So, there is a way to read the current html DOM, including all elements that were added dynamically. I tried various .live applications, but not joy.

Thanks in advance.

+3
source share
1 answer
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript" src="jquery-1.4.2.min.js"> </script>
</head>

<body>
<script type="text/javascript">
$(document).ready(function(){
console.log($("body").html());
var new_element = $('<div id="2-div">test2 </div>');
new_element.appendTo("body");
console.log($("body").html());
});

 </script>

<div id="1-div">test-1</div>
</body>
 </html>

, . HTML . - , , .

0

All Articles