- create your variable that stores all the objects that have been assaigned a class
- Create a For loop so it applies your condition to all objects
- Create an If statement to apply your condition to the objects with a given attribute that contains a certain value.
- By using .cssText command you can apply all your CSS rules as normal between the quotation marks.
How To Style A Class By Attribute Value Real Life Example:
var elements = document.getElementsByClassName('variable-item');
for (var i = 0; i < elements.length; i++) {
if (elements[i].getAttributeNode('data-wvstooltip').value == "None") {
elements[1].style.cssText = "color: red;";
} else {
elements[i].style.cssText = "color: gray; ";
}
}