1
<a href="#">Hide Me</a>

How do I find a link with text "hide" in it. I know how to find links by attributes but can't figure out how to find link by its text.

eozzy
  • 66,048
  • 104
  • 272
  • 428

2 Answers2

3
$('a:contains(Hide)')

Note that contains is case sensitive.

$('a:contains(Hide)').click(function() { $(this).hide() });
David Hedlund
  • 128,221
  • 31
  • 203
  • 222
  • @dittodhole: it sure does. the same goes for attribute selectors, `a[href=#]`. i'm not sure if any version is officially recommended over the other, but both work. – David Hedlund Jan 19 '10 at 12:16
1
$('a:contains("Hide")');

see this post
see jQuery docu

Community
  • 1
  • 1