Reputation: 50432
I have some html that looks like this:
<dl>
<dt>Label 1</dt>
<dd>
Yadda yadda yadda
</dd>
<dt>Label 2</dt>
I would like to get at the text that says "Yadda yadda yadda". I figure I need to tell jQuery to do something like "Select tag where the parent is a tag that contains the text "Label 1".
What is a good way to do this?
Thanks!
Upvotes: 0
Views: 605
Reputation: 817238
It is not the parent tag, it is the previous sibling. You can do:
var text = $('dt:contains("Label 1")').next().text();
Of course this would also select any other dt
element that contains the text Label 1
.
If the element is always the first dd
element, you can also do:
var text = $('dl dd').eq(0).text();
Upvotes: 4