javascript - creating cascaded elements in JQuery -
i've got following assignment:
create div button dynamically, , in turn should create (div button), on.
yet following code not work:
<div id="m-0"> <div id="m-0c"></div> <input id="add_container" name="add_container" class="cua" type="button" value="addition container" > </div>
and jquery code is:
$(document).ready(function() { $(".cua").live("click", function(e){ var father = $(this).parent(); var id_new=father.attr('id')+'.m-'; var number=0; while( $('#'+id_new+number).length ){ number=number+1; } id_new=id_new+number; alert('here '+id_new); $('#'+father.attr('id')+'c').append('<div id="'+id_new+'"><div id="'+id_new+'c"></div><input id="add_container" name="add_container" class="cua" type="button" value="addition container" ></div>'); }); });
a click on first button works, next click on newly created button not working.
try using on()
..
$(document).on('click','.cua',function(e){ var father = $(this).parent(); var id_new=father.attr('id')+'.m-'; var number=0; ..... });
Comments
Post a Comment