jquery - getting rel attr of link and using as text recurring -
i'm trying rel attr set of links in slider, use text control. i've got working except lists first rel multiple times, instead of multiple rels once.
my jquery is
jquery("#slider li a").each(function() { var yearvalue = $(this).attr('rel'); jquery('#controls li a').text(yearvalue); });
and output html is
<div id="slider"> <ul> <li><a rel="foo" href="#"><img src="image1.jpg" alt="alt" /></a></li> <li><a rel="bar" href="#"><img src="image2.jpg" alt="alt" /></a></li> </ul> </div> <ol id="controls"> <li id="controls1" class="first"><a href="javascript:void(0);" rel="0">foo</a></li> <li id="controls2" class="current"><a href="javascript:void(0);" rel="1">foo</a></li> </ol>
i need ol have foo , bar, not foo , foo
any ideas? appreciated
try this,
jquery("#slider li a").each(function() { var index = $(this).parent().index(); var yearvalue = this.rel; jquery('#controls li').eq(index).find('a').text(yearvalue); });
Comments
Post a Comment