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

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -