jQuery :contains selector to search for multiple strings

Posted by Stefan on Stack Overflow See other posts from Stack Overflow or by Stefan
Published on 2010-03-10T12:29:30Z Indexed on 2010/03/13 12:55 UTC
Read the original article Hit count: 470

Assuming i have:

<li id="1">Mary</li>
<li id="2">John, Mary, Dave</li>
<li id="3">John, Dave, Mary</li>
<li id="4">John</li>

If i need to find all <li> Elements which contain "John" and "Mary", how would i construct the jQuery?

A search for a single string seems easy:

$('li:contains("John")').text()

I am looking for something like the following pseudo code:

$('li:contains("John")' && 'li:contains("Mary")').text()

Thanks!

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about contains