How can I check to know if an HTML element is visible or not (hidden) using Javascript and/or JQuery?
And also how can I change the visibility of that element if possible?
thanks in advance!
How can I check to know if an HTML element is visible or not (hidden) using Javascript and/or JQuery?
And also how can I change the visibility of that element if possible?
thanks in advance!
it’s easy use this : $(element).is(":visible")
it returns true
if the element is visible, otherwise false
.
P.S. replace
"element"
by the real HTML element ID.
You can simply check for a HTML element visibility using JQuery
this way:
$(element).is(":visible");
$(element).is(":hidden");
Hidden
and Visible
you can do it this way:if ($('.target').is(':hidden')) {
$('.target').show();
}
else {
$('.target').hide();
}
if ($('.target').is(':visible')) {
$('.target').hide();
}
else {
$('.target').show();
}
hope that helps
If you need to be sure that the element is invisible or visible you have to check:
This list could be not complete.