I am trying to use jQuery to select a div, but ignore all divs
selected that are children of a selected div. No divs
have any other way to identify them other than an HREF
that I am matching. For example:
outerdiv = $('a[href^="http://bizmate."]').closest('div');
outerdiv.prepend("This was selected")
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>Won't be selected
<div>
Powered by <a href="http://bizmate.in">Bizmate</a>
<div>
Powered by <a href="http://bizmate.in">Bizmate</a>
<div>
Powered by <a href="http://bizmate.in">Bizmate</a>
</div>
</div>
</div>
</div>
<div>
<div>
Powered by <a href="http://bizmate.in">Bizmate</a>
</div>
</div>
This code selects all the divs
, including the child. How can I limit it to only select the outermost div that satisfies the condition while ignoring the child divs
that also satisfy the given condition?
Edit:
Currently, the example would give:
Won't be selected
This was selectedPowered by Bizmate
This was selectedPowered by Bizmate
This was selectedPowered by Bizmate
This was selectedPowered by Bizmate
I want the result to be:
Won't be selected
This was selectedPowered by Bizmate
Powered by Bizmate
Powered by Bizmate
This was selectedPowered by Bizmate