CSS class validation has property - jQuery
I have these items;
<div class="preview">
<div class="title" style="display:block">
</div>
<div class="preview">
<div class="title" style="display:none">
</div>
<div class="preview">
<div class="title" style="display:none">
</div>
I want to add a class to the preview if the title is "display: none".
Please help me briefly this.
Thanks and regards.
+3
source to share
2 answers
Try the following:
$('.title').is(':not(:visible)').closest('.preview').addClass('foo');
Note that it :not(:visible)
will catch any elements .title
that are hidden due to properties visibility
or display
. If you want to catch display: none
, try this:
$('.title').each(function() {
if ($(this).css('display') == 'none') {
$(this).closest('.preview').addClass('foo');
}
});
+4
source to share