How do I check if an element is visible/hidden in jQuery?
in jQuery
.hide() used to hide element
.show() used to show element
.toggle() used to show/hide element
but is there a function which used to check is element hidden ? or is element already visible ? i mean before to use .show() , .hide() , want to check isHidden() or isVisible() for element in jQuery ?
in JavaScript , .hidden property tell you . is that element is hidden or not.
<div style=" background-color:blue" id='core-blue'>
me blue
</div>
<script type='text/javascript'>
document.getElementById('core-blue').hidden=true; // hide core-blue
...
...
if(document.getElementById('core-blue').hidden){//if core-blue hidden make it visible
document.getElementById('core-blue').hidden=false;
}
</script>
you can check element is visible or not by document.getElementById('id').hidden - true means is hidden , false means its visible.
it will not detect manual display:none . like
[code]
<div style=" background-color:blue;display:none" id='core-blue'>
me blue
</div>
<script type='text/javascript'>
console.log(document.getElementById('core-blue').hidden); //return false even core-blue is not visible
</script>