Neither CSS or jQuery can do that. One suggestion is using closest
.
$(function(){
var element = $('#parent').children('#child');
if (element.closest('.foo').length > 0) {
//you will get true for .foo, #child, or #parent, or div, ...
console.log('Yay!');
} else {
console.log('Duh!');
}
});
Prints 'Yay!'.
That method will check if the element or an ancestor have the class you need. You can ask for a class or for an ID. If you want to check for hidden -as you said- elements, you can try the :hidden
pseudoselector in the regular is
call, rather than hasClass
(Fiddle Here):
<div id="parent" class="foo" style='display: none'>
<div id="child">
</div>
</div>
$(function(){
var element = $('#parent').children('#child');
if (element.is(':hidden')) {
console.log('Yay!');
} else {
console.log('Duh!');
}
});
Prints 'Yay!'.
Another one is this, given your current DOM (Fiddle Here):
$(function(){
var element = $('#parent').children('#child');
if (element.is('.foo *')) {
console.log('Yay!');
} else {
console.log('Duh!');
}
});
Prints 'Yay!'.
However you're using ng-hide
, which usually means AngularJS. Don't know what is your intention but if you are not creating a custom directive please avoid using jquery and rethink your problem.