I want to change the background image of a button using Javascript. Here is what I am currently trying, but it is failing.
HTML code -
<tr id="Rank1">
<td><button class="darkSquare"></button></td>
<td><button class="lightSquare" ></button></td>
<td><button class="darkSquare" ></button></td>
<td><button class="lightSquare" ></button></td>
<td><button id="e1" class="darkSquare" ></button></td>
<td><button class="lightSquare" ></button></td>
<td><button class="darkSquare" ></button></td>
<td><button class="lightSquare"> </button></td>
</tr>
JavaScript Code
initializer();
function initializer()
{
var tableRow = document.getElementById("Rank1");
var buttons = tableRow.getElementsByTagName("button");
for(b in buttons)
{
console.log(b.toString());
b.style.backgroundImage = "url('darkSquare.jpg')";
}
}
In the console, I get an error saying b.style is undefined.