Check if Element is Hidden with is(“:visible”)

is(":visible") will test the visibility of an element and will return true if the selected element is visible, or it will return false if it is hidden.

As you’ve noticed, it is the direct opposite of the .is(":hidden") method. This means that both of them can’t return the same value for the same element. Not at the same time at least.

Let’s test it

var myElement = ".first-element";
console.log(myElement + " is visible?: " + $(myElement).is(":visible"));

As expected, it will output a false value:

.first-element is visible?: false

Note that you would also get the same results when working with the hidden inputs:

<input type="hidden" class="inp-element" value="3487">

Although the hidden the parameter passed into our input element via the type attribute, it still produces the same result.

Reference: https://stackabuse.com/javascript-check-if-element-is-hidden-with-jquery/

Leave a comment

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