javascript - Better way to rewrite this .each() function -
this code works fine, i'm guessing there better way rewrite in either jquery or vanillajs.
the main goal is:
- to clone specific child elements parent element
- create new elements cloned child elements
append newly created elements new container.
$('.grid-block').each(function(){ var slide = $('<div class="slide"></div>'); $(this).find('.asset-holder img') .clone() .appendto(slide); $(this).find('.asset-tools') .clone() .appendto(slide); slide.appendto('.gallery-slider'); });`
i don't know need iteration, combine calls find()
:
var slide = $('<div class="slide"></div>'); $('.grid-block').find('.asset-holder img, .asset-tools').clone().appendto(slide); slide.appendto('.gallery-slider');
Comments
Post a Comment