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.
您需要使用.last()
或:last
来获取所需的div,因为所有父级也都包含该文本
$('div:contains("Your personal data has been updated.")').last()
All parents divs contain this text too. Use id for your selector or add only-child suffix
$( "div ... :only-child" )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.