<div id="example">
<div id="test"></div>
</div>
<div id="another">Blah</div>
I want to set $('#another').hide() but only if #example contains a child element called#test, is this possible? It seems like it would be.
I think what you are looking for is the following
if (jQuery.contains($('#example'), $('#test')) {
$('#another').hide();
}
This might work as well, not sure off the top of my head.
if ($('#test', $('#example')).size() > 0) {
$('#another').hide();
}
size(). Haven't seen that in a long time! length ftw.$('#test').has('#example') { $('#another').hide(); }jQuery manual suggests to use:
if ($('#parent').has('#child').length) {
//do something
}
it's pretty simple.
$(document).ready(function(){
if($('#example').children('#test').length > 0)
{
$('#another').hide();
}
});