Currently, I am utilizing CSS selectors to target specific elements and now I want to be able to identify those elements using javascript. My approach involves setting the color of these elements in css and then retrieving them based on their color. However, an issue arises as style.backgroundColor only returns the color if an inline style is applied.
To see my attempt in action, you can check out this demo here.
The CSS I used is as follows:
div{background-color: lightgrey;}
And for the JavaScript part:
alert(document.getElementById("myDiv").style.backgroundColor);
I am currently looking for a solution to make color detection work without relying on inline styles or maybe someone has a better suggestion on how to identify affected elements by CSS selectors. It's worth noting that I would like to avoid using jQuery for this task.