Reputation: 3688
I have these elements;
<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 short this.
Thanks & Regards.
Upvotes: 3
Views: 1953
Reputation: 337560
Try this:
$('.title').is(':not(:visible)').closest('.preview').addClass('foo');
Note the :not(:visible)
will catch any .title
elements who are hidden due to the visibility
or display
properties. If you only want to catch display: none
try this:
$('.title').each(function() {
if ($(this).css('display') == 'none') {
$(this).closest('.preview').addClass('foo');
}
});
Upvotes: 4