In jQuery:
e.is(':visible');
checks if an element is displayed or not.
Is there an function in jQuery to check if an element has the attribute visibility to hidden or visible?
Now I have to make that function myself. But i want to use the jQuery function instead if it exists.
The function I made:
$.fn.isVisible = function() {
return ($(this).css('opacity') != '0' && $(this).css('visibility') !== 'hidden');
};
To extend my example: JsFiddle
The real question is: Is there a jQuery function or not?
To check if an element is hidden or not, jQuery :hidden selector can be used. .toggle() function is used to toggle the visibility of an element.
You can use the jQuery :visible selector to check whether an element is visible in the layout or not. This selector will also select the elements with visibility: hidden; or opacity: 0; , because they preserve space in the layout even they are not visible to the eye.
Projects In JavaScript & JQuery You can use .is(':visible') selects all elements that are visible.
jQuery hide() Method The hide() method hides the selected elements. Tip: This is similar to the CSS property display:none. Note: Hidden elements will not be displayed at all (no longer affects the layout of the page).
You can check css property visibility is set to visible or hidden.
if ($("#element").css("visibility") === "visible") {
//...
}
or in your case:
$.fn.isVisible = function() {
return $(this).css('visibility') === 'visible';
};
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