If element contains no elements with certain css

geftaxoff

New Member
I have a jQuery script to hide an element if it does not contain a certain element:\[code\]<script type="text/javascript"> $(document).ready(function(){ $("div.main div p").not(":has(span)").css("display","none");});</script><div class="main"> <div> <p>Hello <span>OK</span></p> <p>Hi</p> </div> <div> <p>Yo</p> </div></div>\[/code\]This script would hide the \[code\]<p>Hi</p>\[/code\] and the \[code\]<p>Yo</p>\[/code\] text.How can I check if the divs under \[code\]div.main\[/code\] contain no \[code\]<p>\[/code\] elements containing \[code\]<span>\[/code\], or another way: if all \[code\]<p>\[/code\] elements under a div are set to \[code\]display:none\[/code\]?... And set those divs to \[code\]display:none\[/code\].So the HTML output would be:\[code\]<div> <p>Hello <span>OK</span></p> <p style="display:none">Hi</p></div><div style="display:none"> <p style="display:none">Yo</p></div>\[/code\]
 
Back
Top