javascript - jquery on click event not firing when using jquery 1.11.3.min.js . -
as per below html controls , if try change "id" of submit "save" , click of save not working then.
html
<html> <head> </head> <body> <input type="button" value="submit request" id="submit"class="buttonclass"/> <input type="button" id="cancel" value="cancel" class="buttonclass" /> </body> </html
js code below :
$("#submit").on({ click: function () { $(this).attr('id', 'save'); return false; } }); $("#save").on({ click: function () { alert("save event fired"); } });
you aren't binding click event #save because id #save exists after submit button has been pressed (there no #save on load). if put click event on body , accept #save, can bubble event , handle there.
$("#submit").on('click', function (e) { e.stoppropagation() alert("submitted fired"); $(e.target).attr('id', 'save'); $(this).unbind('click'); }) $("body").on('click', '#save', function (e) { alert("save event fired"); })
https://jsfiddle.net/6lchafwa/1/
if answer looking for, press green tick on left.
Comments
Post a Comment