Friday, 15 August 2014

jquery - Trying to set a CSS property on one element while iterating a different one -



jquery - Trying to set a CSS property on one element while iterating a different one -

i've got boxes want lay out position:absolute;.

$('.tt-sessions-in-room').each(function(index){ $(this).css('left', left); left = left + $(this).width() + extra_width; });

which lovely. want match other boxes same absolute position above them.

if seek matching in same .each() so

$('.tt-sessions-in-room, .tt-roomname').each(function(index){

then iterates through 1 long list, , .tt-roomnames positioned off right.

how grab each element of .tt-roomname , set left css? current thinking build array , each of them @ same time iterate through array - there improve way using .each() ?

got it. can utilize (index) iterate, checking other element's .eq()

$('.tt-sessions-in-room').each(function(index){ $(this).css('left', left); left = left + $(this).width() + extra_width; $('.tt-room').eq(index).css('left', left); });

jquery css

No comments:

Post a Comment