dimanche 10 juillet 2016

How to clone an element and insert it multiple times in one go?


How can I clone an element and insert it 5 times right after each other? This of course is the base statement: $('.col').clone().insertAfter('.col'); Here's what I need to get: <div class="col" id="original"> </div> <div class="col"> </div> <div class="col"> </div> <div class="col"> </div> <div class="col"> </div> <div class="col"> </div> The selector doesn't need to be using an unique id, it can also be a class selector. I could just repeat the base statement four times but there must be a more elegant way?

Aucun commentaire:

Enregistrer un commentaire