javascript - Remove internal selected div created dynamically -


i've been looking around couldn't find solution yet. code this:

$('#adddiv').click( function() {            var divnum = divnum + 1;           var newdiv = document.createelement('div');           var dividname = 'mydiv';           newdiv.setattribute('id',dividname+divnum);           newdiv.classname = 'imgdiv';  });  $('#cont-div').on('click', function(e) {          //remove clicked div  }); 

i have div named "cont-div" contains dynamically created divs. solution simple, can't find way identify clicked div inside 'cont-div' can remove it.

you can use event delegation since divs created dynamically:

$('#cont-div').on('click', 'div', function(e) {          //remove clicked div         $(this).remove();  }); 

Comments