I'm using jquery to change the html content of a div when certain buttons are clicked. The code works fine on the first change. But if I then click a different button to change it to something else, I get a blank div (no text). I know all buttons work because when I try each of them first, they change the content correctly.
Do I have to re-set something after each change to get the next one to work?
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