views:

44

answers:

2
<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.

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

Note that contains is case sensitive.

$('a:contains(Hide)').click(function() { $(this).hide() });
David Hedlund
does it work without the quotes?
Andreas Niedermair
@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
ah ... didn't know :) thanks for the info!
Andreas Niedermair
+1  A: 
$('a:contains("Hide")');

see this post
see jQuery docu

Andreas Niedermair