It is possible to toggle the visibility of an element, using the functions .hide()
, .show()
or .toggle()
.
How would you test if an element is visible or hidden?
It is possible to toggle the visibility of an element, using the functions .hide()
, .show()
or .toggle()
.
How would you test if an element is visible or hidden?
You can use the
hidden
selector:And the
visible
selector:This works for me, and I am using
show()
andhide()
to make my div hidden/visible:Example:
Maybe you can do something like this
To check if it is not visible I use
!
:Or the following is also the sam, saving the jQuery selector in a variable to have better performance when you need it multiple times:
Also here's a ternary conditional expression to check the state of the element and then to toggle it: