So I'm trying to see if a cell has a red background, when I put test in the inputbox
and click the button, I receive the message "this is not red". Could someone please
explain to me how I could make it say "this is red"?
var colors = ["rgb(255, 0, 0)"];
function testfunction() {
var location = document.getElementById("userinput").value;
if (document.getElementById(location).style.backgroundColor == colors[0]) {
alert("This is red");
} else {
alert("This is not red");
}
}
.red {
background-color: rgb(255, 0, 0);
}
<table>
<tr>
<td id="test" class="red"> a1 </td>
<td id="test2"> b1 </td>
</tr>
<tr>
<td id="test3"> a2 </td>
<td id="test4" class="red"> b2 </td>
</tr>
</table>
<input id="userinput" type="text">
<button id="button" onclick="testfunction()"> Button </button>