Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to select all DOM elements that have a certain class but also have certain CSS attribute value using JavaScript?

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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

const elements = document.querySelectorAll('.date[style*="display: none"]');
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading