我正在尝试制定一个复杂的 jQuery 选择。我有一个数组,我需要选择包含链接 a.bar
的 div.foo
,并且该链接的 href
包含任何字符串在数组中。
例如:
<html>
<div class=foo>
some text
<a class=bar href=example.com?q=widget&id=23456789>search</a>
</div>
</html>
和 jScript
widgets[0]='12345678';
widgets[1]='23456789';
widgets[2]='34567890';
我想突出显示此 div,因为查询字符串包含 23456789
,它是 widgets[]
中的元素之一。
谢谢
最佳答案
$('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();
}
关于jQuery 选择包含链接的元素,该链接包含数组的任何元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2699072/