How to make this code work? (Javascript) -


i have following code:

 var dateclasses = $('.dateclass'); // array of dateclasses  var contentclasses = $('.contentclass'); // array of contentclasses   for(var i=0; i< math.min(dateclasses.length,contentclasses.length); i++) {  var frame = $("<div>", {class: "frame"}); // create frame node  var timelinedate = $("<span>",{class: "timeline-date"});  var timelinecontent = $("<div>",{class: "timeline-content"});   //append dateclass timeline-data:  timelinedata.append(dateclasses[i]);    //append contentclass timeline-content:  timelinecontent.append(contentclasses[i]);   //append frame  frame.append(timelinedata);  frame.append(timelinecontent);  } 

and:

<span class="dateclass">date1</span> <span class="dateclass">date2</span> <span class="dateclass">date3</span> <div class="contentclass">content1</div> <div class="contentclass">content2</div> <div class="contentclass">content3</div> 

but i'm not sure why wouldn't work, advise? :/

http://jsfiddle.net/8qrlh2wz/

thanks time

edit: i apologize everyone, submitted post quickly totally deserve downvotes. i'd indeed (as 1 of mentioned) move dateclass elements timeline-date, , contentclass timeline-content. need 1 frame per dateclass , contentclass group of elements: means there should 3 frame in total

i think trying move dateclass elements timeline-date , contentclass timeline-content.

but in code creating new elements, not added dom try

var dateclasses = $('.dateclass'); // array of dateclasses var contentclasses = $('.contentclass'); // array of contentclasses  $('.frame .timeline-date').append(dateclasses); $('.frame .timeline-content').append(contentclasses); 

demo: fiddle

if want keep loop

var dateclasses = $('.dateclass'); // array of dateclasses var contentclasses = $('.contentclass'); // array of contentclasses  var timelinedata =$('.frame .timeline-date'); var timelinecontent =$('.frame .timeline-content');  (var = 0; < math.min(dateclasses.length, contentclasses.length); i++) {     //append dateclass timeline-data:     timelinedata.append(dateclasses[i]);      //append contentclass timeline-content:     timelinecontent.append(contentclasses[i]); } 

demo: fiddle


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -