2

How would I go about clicking a link using jQuery, with the text inside the link.

I.E.:

<a href="/node/1744650/nodequeue">Nodequeue</a>

I want to click this link based entirely on the fact that Nodequeue is inside the link.

Steven Matthews
  • 9,705
  • 45
  • 126
  • 232

2 Answers2

2

You could use the contains: selector:

$('a:contains("Nodequeue")').click();

For more information about the selector, have a look at the documentation for it here. Please note that it is case-sensitive, if you are looking for case insensitive search, have a look here.

Community
  • 1
  • 1
Niklas
  • 29,752
  • 5
  • 50
  • 71
  • I tried that, and it kept giving me an error message. One of my other questions touches on this error message, I will post it here later (I am at work currently and do not have the ability to generate the debug code atm) – Steven Matthews Jul 07 '11 at 14:48
1
$('a:contains("Nodequeue")').trigger('click');
Naftali
  • 144,921
  • 39
  • 244
  • 303