BOTJr. BOTJr. - 2 months ago 11
jQuery Question

get hidden elements from a set of elements

I have a filter that returns the products that has to be displayed.I store those elements inside a variable.

enter image description here

console.log
of this variable would be something like above.Now The returned set elements contains some of them with style
display="none"
. I want to select those with
display='none'
and display exactly two of the selected ones.

DOM structure of elements would be something like this

<body>
<ul class="products">
<li class="product" data-company="something" data-flavour="something"></li>
<li class="product" data-company="something" data-flavour="something"></li>
.
.
.
.

<li class="product" data-company="something" data-flavour="something"></li>
</ul>
</body>


How could i achieve this with jquery/Javascript?

Answer

Are you storing the nodes in an array? That's what it looks like to me and if that is the case you can do something like this.

nodes.filter((node) => node.style.display === 'none')

or if you can't use arrow syntax:

nodes.filter(function (node) { return node.style.display === 'none' })
Comments