开发者

get href of link with display:block property

开发者 https://www.devze.com 2023-01-14 18:28 出处:网络
Here\'s is what I\'m trying to get <a href=\"default.aspx?propid=BARN\" class=\"topbook\"></a>

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消