开发者

jQuery select element containing a link that contains any element of array

I am trying to work out a complicated jQuery selection. I have an array, and I need to select div.foo that contains a link a.bar and the link's href contains any of the strings in the array.

For example:

<html>
<div class=foo>
  some text
  <a class=bar href=example.com?q=widget&id=23456789>search</a>
</div>
</html>

and jScript

widgets[0]='12345678';
widgets[1]='23456789';
widgets[2]='34567890';

I want 开发者_如何学JAVAto highlight this div because the query string contains 23456789 which is one of the elements in widgets[].

Thanks


$('div.foo > a.bar[href*=23456789');

select all a which contains '23456789' in the href attributes with the bar class which are direct descendant of all div with a class foo.

for (num in widgets)
{
    $('div.foo > a.bar[href*=' + num + ']').doSomething();
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜