", "dateCreated": "0000-00-00 00:00:00", "upvoteCount": 1, "url": "https://www.arrayoverflow.com/question/how-do-i-check-if-an-element-is-visible-hidden-in-jquery/248#253", "author": { "@type": "Person", "name": "fatso" } } ] } }
Asked 7 years ago
9 Jan 2017
Views 830
yogi

yogi posted

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 ?
fatso

fatso
answered Nov 30 '-1 00:00

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>
Post Answer