Reputation: 1857
I have the following html code
<ul id="selector">
<li> <a> first </a> </li>
<li> <a> Second </a> </li>
</ul>
I want to get the anchor with specific text and trigger a click event on it.
$("#selector li").find('a').contains('first').click()
Error :
$(...).find(...).contains is not a function
Upvotes: 0
Views: 4186
Reputation: 82241
You are missing the double quote "
at beginning of li selector. you also need to use selector :contains
instead of .contains()
because:
.contains() Check to see if a DOM element is a descendant of another DOM element.
and
:contains Select all elements that contain the specified text.
$("#selector li").find('a:contains(first)').click()
Upvotes: 2