Reputation: 840
I have following situation:
<div id="content">
<h4 class="page-header">Editing personal data</h4>
<div class="alert alert-success" id="personal-data-changed" style="display: block;">
Your personal data has been updated.
</div>
I am trying to get div with text "Your personal data has been updated." using this:
$('div:contains("Your personal data has been updated.")');
But I get all divs up. (Parent divs). Is possible to get only one div.
Edit:
Thanks for all answers.
Upvotes: 0
Views: 101
Reputation: 4917
All parents divs contain this text too. Use id for your selector or add only-child suffix
$( "div ... :only-child" )
Upvotes: 1
Reputation: 32591
You need to use .last()
or :last
to get the desired div, because all the parents also contains that text
$('div:contains("Your personal data has been updated.")').last()
Upvotes: 1