开发者

jQuery - How to get a div without an <a> from multiple div's

开发者 https://www.devze.com 2023-04-10 19:41 出处:网络
I\'m new to all this so I apologise if my question is \'primitive\'. I\'ve looked all over and can\'t find the answer that suits my specific problem, which is...

I'm new to all this so I apologise if my question is 'primitive'. I've looked all over and can't find the answer that suits my specific problem, which is...

I have several div's all with a the same class name and all with individual id's. All but 1 of the div's also contain an anchor tag.

I'm trying to get the id of only the div with an id that doesn't have an anchor tag - how do i do it? - also, I need to do it in a way that would work if I changed which div (with an id) didn't have the anchor, ie I would get the id of whichever div had the anchor removed (only 1 div with an id within the divContainer div would have no anchor).

eg: (occurs with other div's etc on page)

<div id="divContainer">
<div id="1" class="div"><a id="a1" class="a" href="blah blah">Blah</a></div>
<div class='other div'></div>
<div id="2" class="div"><a id="a2" class="a" href="blah blah">Blah</a></div>
<div class='other div'></div>
<div id="3" class="div"><a id="a3" class="a" href="blah blah">Blah</a></div>
<div class='other div'></div>
<div id="4" class="div">Blah</div>
<div class='other div'></div>
<div id="5" class="div"><a id="a5" class="a" href="blah blah">Blah</a></div>
<div class='other div'></div>
<div id="6" class="div"><a id="a6" class="a" href="blah blah">Blah</a></div>
</div>

I hope that makes sense! Happy to answer any 开发者_如何转开发questions needed to help! Thanks in advance to the guru's with the knowledge to get me out of my hole.


You want

$('div:not(:has(a))')
0

精彩评论

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

关注公众号