Is there any way - any jQuery selector (i did found none on / ), which can be used as exact match?
:contains() is almost what i need, but not exactly. ":contains" searches in each element regex like this:
.*<query>.*
Which means, if i need to find link, which looks exactly like this:
<a href="#">Baxter</a>
And use this:
$("a:contains('Baxter')")
It matches also this, which i don't want to match:
<a href="#">I'm Peter Baxter, how are you?</a>
I know, that I can just take all elements and pare their content in the cycle, but I want to be sure, there's no easier way.
Is there any way - any jQuery selector (i did found none on http://api.jquery./category/selectors/ ), which can be used as exact match?
:contains() is almost what i need, but not exactly. ":contains" searches in each element regex like this:
.*<query>.*
Which means, if i need to find link, which looks exactly like this:
<a href="#">Baxter</a>
And use this:
$("a:contains('Baxter')")
It matches also this, which i don't want to match:
<a href="#">I'm Peter Baxter, how are you?</a>
I know, that I can just take all elements and pare their content in the cycle, but I want to be sure, there's no easier way.
Share Improve this question asked Jan 12, 2011 at 20:05 Radek SimkoRadek Simko 16.1k18 gold badges72 silver badges110 bronze badges1 Answer
Reset to default 12No, but it would be trivial to add as a plugin:
$.expr[':'].contentIs = function(el, idx, meta) {
return $(el).text() === meta[3];
};
You can then use this as $('a:contentIs("Baxter")')