How can I change the style of the label element (let's say set it to red) in pure JS?
-
How can I change the style of the label element (let's say set it to red) in pure JS?
I realized that you can change the style only if you set the class or id, but I need to change the style of all label elements on the page in general.
How to do it?JavaScript Anonymous, Dec 1, 2020 -
Only if you set a class or id
It's not like that.
https://developer.mozilla.org/en/docs/Web/API / Docu ...
You get a list of items. You iterate over them. Change the style for each.Eleanor Reese -
let labels = document.querySelectorAll('label');
labels.forEach((label)=>{
label.style.color='red';
});Anonymous
2 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!