How to select all DOM elements that have a certain class but also have certain CSS attribute value using JavaScript?
For example, I want to select all the elements that have class "date"
but have a display: none
CSS attribute.
I know it has something to do with querySelector
/ querySelectorAll
but I am unable to find such example (all the examples I stumbled upon either select by class or by CSS attribute but not by both).
Question posted in Javascript
A very good W3school tutorial can be found here.
A very good W3school tutorial can be found here.
2
Answers
you can do this by combining the class selector with the attribute selector in the querySelector(All) method. Here is how you can select all elements with the class date and a CSS attribute display: none for example.
I don’t know if you can do this with
querySelector
/querySelectorAll
, but you can use this method: