Filter out jQuery elements that have CSS style mapping: none

The selector gave me a set of elements. From a set of elements, I have 1 or 2 elements displaying CSS attributes: none. I have to remove these items and get the items that are displayed. How can this be done using jQuery?

+6
source share
3 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 that the display attribute is not none , and remove those who are.

+6
source
 $("selector").is(":visible") 

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

 $("selector:visible") 
+8
source

You can use filter ()

 var listWithoutDisplayNone = elementList.filter(function(){ if($(this).css('display') != 'none') return $(this); }); 
+2
source

All Articles