JQuery.click () not working after html change
It's pretty simple, I have a button and when you click on it it changes. But after this change the event .click()
doesn't work on it but works on divs that are already on the page
$('#editBioButton').click(function(){
/* 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 */
$('#saveBioText').click(function(){
alert('itowrks');
});
});
+3
source to share
5 answers
$('#editBioButton').click(function(){
var oldBio = $('.bioText').html();
$('.bioText').replaceWith(' <textarea name="newBio" rows="6" cols="30" > ' + text + ' </textarea>');
$('#editBioButton').replaceWith(' <div id="saveBioText"> Save Changes </div> ');
$(document).on('click', '#saveBioText', function(){
alert('it works');
});
});
+2
source to share