Grasshopper
Grasshopper

Reputation: 1808

How to get specific hyperlink object based on text using Jquery

<a href="test1" onclick="calltest1()"> X1  </a>
<a href="test1" onclick="calltest2()"> X2 </a>
<a href="test1" onclick="calltest3()"> X3 </a>

I need to get the hyperlink object based on the text inside ex: x1 and bind a function to it. Can you please suggest the best way to achieve this?

Upvotes: 0

Views: 62

Answers (1)

Bryan
Bryan

Reputation: 1453

You can use the jQuery Contains selector https://api.jquery.com/contains-selector/

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

Upvotes: 3

Related Questions