Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery is(:visible) for visibility : hidden

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?

like image 492
Nebulosar Avatar asked Apr 28 '17 10:04

Nebulosar


People also ask

How do you check hide or show in jQuery?

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.

Is jQuery visible or not?

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.

Is div visible jQuery?

Projects In JavaScript & JQuery You can use .is(':visible') selects all elements that are visible.

Is jQuery hide () is equivalent to?

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).


1 Answers

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';
};
like image 142
athi Avatar answered Sep 30 '22 07:09

athi