Reputation: 1367
I have a div with id="poidiv"
whose display
is 'none'
initially. Now I want to load it more than once with a loop (the max value of the loop is dynamic). I tried it with JQuery .append().clone()
.
Here is the example code--
$(document).ready(function(){
$("#levelnext").click(function(){
for(i=1; i<=level; i++){
$("#leveldiv").append($("#poidiv").clone().removeAttr("id"));
}
});
});
But because the display
of "poidiv"
was initially 'none'
, it does not appear with this piece of code. Now if I want to show it with .show()
before the loop starts, the loop is not working in a good manner. What might be a good solution in this situation?
Upvotes: 0
Views: 336
Reputation: 630489
You can .show()
in the chain, like this:
$("#leveldiv").append($("#poidiv").clone().removeAttr("id").show());
Upvotes: 3