Thomas Depole Thomas Depole - 11 days ago 6x
jQuery Question

Jquery .click() doesn't work after html has been changed

It's pretty basic, I have a button, and when you click it, it changes. But after it changes the

event doesn't work on it, but works on divs that are already on the page

/* this captures html text and replaces it with textbox */
var oldBio = $('.bioText').html();
$('.bioText').replaceWith(' <textarea name="newBio" rows="6" cols="30" > ' + text + ' </textarea>');
/* this switches button */
$('#editBioButton').replaceWith(' <div id="saveBioText"> Save Changes </div> ');
/* this div won't react when clicked */



I ran into the same problem before. Turns out jQuery loses all bindings on elements that are added after loading. You should use the delegate method

$("#editBioButton").delegate("#saveBioText", 'click', function(){