I have some code that I need to change via javascript because I cannot edit the code myself (it is created by a platform I use for my website)
<tr style="color:#8C4510;background-color:#FFF7E7;">
What I want to do is wherever this appears, replace the colors with other ones, but it needs to be only for these colors and not all <tr>
tags.
Example: replace #8C4510
with #CCCCCC
I am aware of getElementsByTagName, but unsure how to target certain styles within that element to find and replace with something else.
Here is what I tried:
var bgcolor = document.querySelectorAll("*[style]");
for (var i=0; i<bgcolor.length; i++) {
var style = bgcolor[i];
if (background-color == '#FF8000') {
background-color = '#ed5900';
if (background-color == '#E5F2E5') {
background-color = '#f8f8f8';
}
if (background-color == '#FFF7E7') {
background-color = '#f8f8f8';
if (background-color == '#855129') {
background-color = '#8ebe3e';
}
if (background-color == 'orange;') {
background-color = '#8ebe3e';
}
if (color == '#8C4510') {
color = '#8ebe3e';
}
}
And
function changeBGAll() {
var bg = document.querySelectorAll("*[style]");
for (var i = 0; i < bg.length; i++) {
if (bg[i].style.indexOf('FF8000') !== -1) {
bg[i].style = bg[i].style.replace("FF8000", "ed5009");
}
}
}
changeBGAll();