Easy Tutorial
❮ Android Tutorial File Android Tutorial Intro ❯

English: ## jQuery Determine if an Element is Hidden

Category Programming Techniques

This article introduces how to use jQuery to determine if an element is hidden:

// Check the CSS property display: [none|block], ignore visibility: [true|false]
// Check if the element is visible
$(element).is(":visible");

// Check if the element is hidden
// The same works with hidden
$(element).is(":hidden");

The following example demonstrates two divs, one visible and one hidden, and uses jQuery to determine if the div elements are hidden:

Example

<div id="div1" style="display:none">
Div1 is a hidden element
</div>

<div id="div2" style="display:block">
Div2 is a visible element
</div>
<script>
if($("#div1").is(":visible")) {
  document.write("Div1 is a visible element<br>");
}

if($("#div1").is(":hidden")) {
  document.write("Div1 is a hidden element<br>");
}

if($("#div2").is(":visible")) {
  document.write("Div2 is a visible element<br>");
}

if($("#div2").is(":hidden")) {
  document.write("Div2 is a hidden element<br>");
}
</script>

** Click to Share Notes

Cancel

-

-

-

❮ Android Tutorial File Android Tutorial Intro ❯