javascript - How to hide my dynamicly created divs? -


i have created script creates divs based on number of li elements , part working fine. hide these div's (dynamicly created) not working. can tell me doing wrong here? thx!!
fiddle here

my code:

$(document).ready(function(){ $(".create").click(function(){ i=''; var count = $("li").length; for(var i=0;i<count;i++){ $('<div class="mydiv" style="width:100px;height:100px;background-color:red;border:1px solid #000000;"></div>').appendto('body'); } });  $('.check').click(function(){ var getdivs= $('div').length; alert(getdivs); }); //why not working? $('div').click(function(){ $(this).hide(); }); }); 

try instead (and attach click event when create div):

$('<div class="mydiv" style="width:100px;height:100px;background-color:red;border:1px solid #000000;"></div>') .click(function(){  $(this).hide(); }) .appendto('body'); 

Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -