views:

38

answers:

1

Here's is what I'm trying to get

<a href="default.aspx?propid=BARN" class="topbook"></a>

The above link should clone the sidelink that has display:block

<a href="default.aspx?propid=FARM" class="sidelink"></a>
<a href="default.aspx?propid=HANW" class="sidelink"></a>
<a href="default.aspx?propid=BARN" class="sidelink" style="display:block"></a>

But I'm getting

<a href="default.aspx?propid=FARM" class="topbook"></a>

Because it is copying the first instance of sidelink href

Here's my code

$('.topbook').attr('href', $('.sidelink').attr('href'));

Hope this helps

Thanks

Jamie

+2  A: 

You could conceivably use

$('.topbook').attr('href', $('.sidelink[style$="block"]').attr('href'));

but please don't.

Instead, give the .sidelink element whose href you're trying to copy a different class or something, don't use the style attribute to differentiate it from the others.

Yi Jiang
+1 Even better than a different class is to use a unique id.
Emil Vikström