javascript - jquery bind event to new elements -
this question has reply here:
jquery how bind click event on dynamically created elements? 2 answersjava script
$(document).ready(function() { $(".group").click(groupfile); function groupfile(){ alert('clicked!'); } }); function insert() { $("body").append("<div class='group' ></div>"); } html
<div class='group' > </div> <input type="button" value="insertnewelement" id="insert" onclick="insert()"/> when page loaded,on click div.group works , fire groupfile , alert me. when inserted new div.group.onclick div.group function groupfile not worked? please help me
you can utilize jquery on() method delegate events static ancestor shown below:
$(document).ready(function() { $(document).on("click",".group",groupfile); function groupfile(){ alert('clicked!'); } }); read more event delegation
javascript jquery events triggers event-handling
No comments:
Post a Comment