JQuery select element containing a link containing any array element

I am trying to work out a complex jQuery selection. I have an array and I need to select div.foo

which contains a link a.bar

and the link href

contains any of the strings in the array.

For instance:

<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 to highlight this div because the query string contains 23456789

which is one of the elements in widgets[]

.

thanks

+2


a source to share


1 answer


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

      

select everything a

that contains '23456789' in href attributes with class bar which are a direct descendant of all divs with class foo.



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

      

+2


a source







All Articles