开发者

jQuery - Select tag , then child tag with text, then sibling tag

I have some html that looks like this:

<dl>
    <dt>Label 1</dt>
        <dd>
            Yadda yadda yadda
        </dd>
    <dt>L开发者_StackOverflow中文版abel 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!


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();


$("dl dd");

Example: http://fiddle.jshell.net/gE5RR/1/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜