Brian K Brian K - 1 year ago 71
HTML Question

Uisng jQuery to target all dl tags who do not have a specific parent

I'm trying to write a jQuery function that select and receives the text from a website that is designed like this:

<dd> hey </dd>
<dd> how's it goin</dd>
<div style="border:1px solid grey; background:#eee; padding:1em;">
<dd>don't select this</dd>

When I use this code:

transcript += $(this).text();

I select the text within all 3 of the dl tags, however, I only want to select the text within the first 2 dl tags. Is there any way to filter out the text I get by somehow saying that I don't want the text from dl tags that have a parent div with the specific style said in the code I posted? Thanks for the help!

Answer Source

You can try this:

$("dd").not("div dl dd");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download