How does JavaScript filter elements by style?

< H2 > as mentioned, the document.querySelectorAll () method in JavaScript can only filter elements based on attribute (attributes), but how to filter by style? For example, get all the elements that have background pictures on the page? < / H2 >
Apr.15,2021

div-with-image [style ^ = "background-image:"] [style$= ".jpg)"] ?


element has a style attribute, which should be solved by determining the value of a specific attribute.


the simplest and most effective thing is to manually add an attribute, such as data-img, and then document.querySelectorAll ('[data-img]'), otherwise you can't find background-image/background in the style class

.
Menu