开发者

JQuery get live DOM change HTML

Say for example I store the HTML contents of the body tag in a variable in Jquery. So,

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

Then I append some DIVs and make other dynamic changes. Even if I update the variable 'current_html' after every DOM change for some reason it only ever outputs the original DOM content on document load and doesn't contain any of the 开发者_开发技巧appended items....even though I update the current_html variable.

So is there a way to read the current DOM html including all items that have been appended dynamically. I've tried various uses of .live but no joy.

Thanks in advance.


<!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>

I tried with this and it works fine. I was able to see the updated HTML after the new element got appended. Could you post some code if the above thing is not what you meant.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜