I am trying to use jQuery to select a div, but ignore all selected divs that are children of the selected div. No divs have any other way of identifying them than the HREF , which I map to. For instance:
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 divs , including the child. How can I limit it to only selecting an external div that satisfies the condition while ignoring the child divs that also satisfies the given condition?
Edit:
Currently this example will give:
Will not be selected
It was selected according to Bizmate.
It was selected according to Bizmate.
It was selected according to Bizmate.
It was selected using Bizmate.
I want the result to be:
Will not be selected
It was selected according to Bizmate.
Powered by Bizmate
Powered by Bizmate
This has been selected Powered by Bizmate
source share