jquery - Cloning, appending and modifying (frogs) -
in jquery example below, before showing cloned segment of html, how change text "remove frog" "remove frog #99" , add id called "frog99", 99 sequencing number?
<div id='imagebox'> </div> <div class="hidden" id='template'> <span class='alignright'><a href='#' class='deletefrog'>remove frog</a></span> <span class='alignright'><a href='#' class='addfrog'>add frog</a></span> <img src="img/frog.jpg"> </div>
script:
var frogcount = 0; $(document).ready(function() { // listener: add "live" listener link $("#addfrog").live('click', function() { // clone hidden template myclone = $("#template").clone(); // before showing cloned object, change text "remove frog" "remove frog #99". // think should this, myclone.("a").text("remove frog #" + ++frogcount); // add id called "frog99", 99 sequential number. myclone.removeclass("hidden"); $('#imagebox').append(myclone); }); });
change line
myclone.("a").text("remove frog #" + ++frogcount);
to
myclone.find("a.deletefrog") .text("remove frog #" + ++frogcount) .attr('id','frog'+frogcount);
Comments
Post a Comment