javascript - Not able to apply jquery to appended elements -
this question has answer here:
i adding #show_data
button dynamically, not able use jquery on button. hi! data
never logged how add scripts dynamic elements?
<body> <button id="show_fields">show fields</button> <div id="button"></div> <script> $("#show_fields").click(function(){ console.log('hi! fields'); $("#button").html("<button id=\"show_data\">show data</button>"); }); $("#show_data").click(function(){ console.log('hi! data'); }); </script> </body>
use event delegation attaching events dynamically added element:
$("#button").on('click','#show_data',function(){ console.log('hi! data'); });
Comments
Post a Comment