jQuery – check whether an element in the DOM is hidden/Visible

jQuery makes easy to determine if an element is visible or hidden with .is() function or you can use the “hidden” and “visible” selectors.

HTML:

Script:
HTML:

Script:
if ($(‘#myId:visible’).length > 0)
console.log(‘the element is visible’);
else
console.log(‘the element is not visible’);

——–or —–
if( $(‘#myDiv’).is(‘:visible’)) {
// it’s visible, do something
}
else {
// it’s not visible so do something else
}

//Check if an element is hidden
if( $(‘#myDiv’).is(‘:hidden’) ) {
// it’s hidden, do something
}
else {
// it’s not hidden so do something else
}

// for each loop

$(“.myclassElement”).each(function()
{
if ($(this).css(“visibility”) == “hidden”)
{
// handle non visible state
}
else
{
// handle visible state
}
})

Share this nice post:

One thought on “jQuery – check whether an element in the DOM is hidden/Visible

Leave a Reply

Your email address will not be published. Required fields are marked *