Page is a not externally linkable
- Code, Content, and Presentation
-- JavaScript and AJAX
---- multiple use of 'html()' in jQuery


Fotiman - 6:09 pm on May 1, 2012 (gmt 0)


Not sure I understand what you mean. Did you have something like this?

<div id-"change-div">
<div id="text2">2...</div>
<div id="text3">3...</div>
</div>

In other words, is the source of the text that you're copying to change-div nested within change-div to begin with? If so, that would cause a problem because after the first call, the source would no longer exist. In other words, after the first call, your DOM would become:


<div id-"change-div">
2...
</div>


Therefore, subsequent button clicks would result in this:

var htmlStr = ( "#text2" ).html();
// htmlStr = null because #text2 no longer exists in the DOM


Thread source:: http://www.webmasterworld.com/javascript/4448054.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com