philldam - 10 months ago 57
jQuery Question

# Check if more than one element :contains certain text

I'm trying to get a function to fire only if more than one element in a div contains a certain text. I've tried the following approach, but cant seem to make it work:

HTML

<div>
<h2> Some text here </h2>
<p> Some text here too </p>
</div>

jQuery

$(document).ready.(function(){$('h2 && p:contains("text")'). //Do something ();

});

In this case the code should "Do something", because both h2 and p contain "text".

$(document).ready(function() { if ($('div *:contains("text")').length > 1){