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

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

android - CollapsingToolbarLayout: position the ExpandedText programmatically -

Listeners to visualise results of load test in JMeter -