I have a variable called "object". How can I check with JavaScript if it is visible?
I tried !object.getAttribute("dislay", "none")... but that doesn't work.
Could somebody help me please?
Thank you!
function isvisible(obj) {
return obj.offsetWidth > 0 && obj.offsetHeight > 0;
}
as it's implemented in JQuery.
If you use jQuery, the following will return true if the object is visible:
$(object).is(':visible');
If not, you can try these:
if (object.style['display'] != 'none')
But this will work only if display:none
has been set explicitly on this object.
To get value of a display style using javascript you can use:
IE:
document.getElementById('mydiv').currentStyle.display
or
object.currentStyle.display
Others:
document.getElementById('mydiv').getComputedStyle('display')
or
object.getComputedStyle('display')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With