Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter Out JQuery Elements Which Have CSS Style display:none

A selector has yielded me a set of elements. Out the set of elements, I have 1 or 2 elements with CSS attribute display:none. I have to remove these elements and get the elements which have display. How can this be done using JQuery?

like image 539
Abilash Avatar asked Jan 19 '13 06:01

Abilash


2 Answers

You can use .filter().

var displayed = $('mySelector').filter(function() {
    var element = $(this);

    if(element.css('display') == 'none') {
        element.remove();
        return false;
    }

    return true;
});

This will return all elements from your selector thats attribute display is not none, and remove those who's are.

like image 72
Austin Brunkhorst Avatar answered Sep 28 '22 03:09

Austin Brunkhorst


$("selector").is(":visible")

You can also filter out the hidden elements in the original selector:

$("selector:visible")
like image 26
Barmar Avatar answered Sep 28 '22 03:09

Barmar