s gandhi
s gandhi

Reputation: 101

Select element based on text

I want to select an element based on their innertext in JQuery. Below is my Html

<html>
    <body> 
        <a href="fddf">4</a> 
        <a href="fddf">4</a> 
        <a href="fddf">4</a> 
    </body> 
</html>

I want to select all the <a> tags which has text of "4". Any idea how do I do it?

Upvotes: 10

Views: 4314

Answers (2)

Mac
Mac

Reputation: 71

I think the correct way is $("a[outerText='4']"). Contains returns 4,44,444 etc. .

Upvotes: -1

SLaks
SLaks

Reputation: 887195

You're looking for the :contains selector, like this:

$('a:contains("4")')

Upvotes: 16

Related Questions