<div>
<a>
Text1
<img alt="" stc="" />
</a>
<a>
Text2
</a>
</div>
I want to select all anchor elements that have text=text2. I’m looking for something like this:
$('a[text=Text2]')
Edit: Why this is not working? For some some reason, it needs to be in this format:
$('div').find('a').find(':contains("Text2")')
You ask why this doesn’t work:
The reason is,
.find()will search children elements, you want.filter()(because you already selected thea– or you add the:containsto the a find: