[Solved] I want to change texts which have same color without use any class/id etc. via JS [closed]


First of all, you need to make up your mind on what elements really need to be changed. Does your color-change rule apply to literally all elements? – Just paragraphs, labels, or divs?

Upon making the decision, you can try something like this. I am assuming you are trying color change against all elements on the page.

document.querySelectorAll('*').forEach(function(node) {
     if (node.style.color === 'red')
         node.style.color="blue";
});

querySelectorAll returns all elements that match the CSS selector passed as the first parameter. You can use wildcard character * to have it return every element on the screen.

But if you can possibly narrow down your rules and want it to be applied to <label> and <p> elements only, you can simply use it as follows

document.querySelectorAll('label, p').forEach(function(node) {
     if (node.style.color === 'red')
         node.style.color="blue";
});

solved I want to change texts which have same color without use any class/id etc. via JS [closed]