javascript - jQuery : dynamically created div ID can't be selected? -


this question has answer here:

$('#content').droppable({     drop:function(event , ui){           $('<div>').appendto('#content');         $('#content div').load('div.html');                              }                         }); 

below code doesn't select divcontainer id

$('#divcontainer').click(function(){     $('#divcontainer').hide();  }); 

this html page div.html

<div id="divcontainer">     samplediv    </div> 

the div gets added page can't select div using it's id !

the $('#divcontainer').click code needs go inside done section once data loaded in

$('#result').load('div.html', function() {     $('#divcontainer').click(function(){         $('#divcontainer').hide();      }); }); 

or use on() explosion pills said


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -