Reputation: 2777
<div style="visibility:hidden;">a</div>
<div style="visibility:visible;">b</div>
<div style="visibility:hidden;">c</div>
<div style="visibility:visible;">d</div>
if($('*').css( "visibility", "hidden" )
{
$(This).css("display", "none");
}
How to search through entire page to find all elements that visibility :hidden and then add display:none on it? Something like the code above :
Upvotes: 0
Views: 436
Reputation: 207527
You can select it by the style if there is no other elements and the style attribute is exact. In real world scenario, it is not reliable.
$('div[style="visibility:hidden;"]').css('display', 'none')
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div style="visibility:hidden;">a</div>
<div style="visibility:visible;">b</div>
<div style="visibility:hidden;">c</div>
<div style="visibility:visible;">d</div>
Instead select the elements you want and loop over them check that each one is set to visible or hidden.
$('div').each(function () {
if (this.style.visibility === 'hidden') {
$(this).css('display', 'none')
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div style="visibility:hidden;">a</div>
<div style="visibility:visible;">b</div>
<div style="visibility:hidden;">c</div>
<div style="visibility:visible;">d</div>
Upvotes: 1
Reputation: 21477
This works:
$('*').each(function(index, el) {
if (el.style.visibility == 'hidden')
el.style.display = 'none';
});
Upvotes: 0