JSFiddle - React, Tailwind, and code Playground
by Graham Fairweather
HTML
<table id="table01">
<thead></thead>
<tbody>
<tr>
<td id="a01" bgcolor="brown">
<button type="button" name="blabla">
<img class="imgwk" name="wknight" src="http://thumb1.shutterstock.com/thumb_small/98550/98550,1278941506,3/stock-photo-white-chess-knight-56993335.jpg" />
</button>
</td>
<td id="a02" bgcolor="brown">
<button type="button" name="blabla">
<img class="imgwk" name="wknight" src="http://thumb1.shutterstock.com/thumb_small/98550/98550,1278941506,3/stock-photo-white-chess-knight-56993335.jpg" />
</button>
</td>
<td id="a03" bgcolor="brown">
<button type="button" name="blabla">
<img class="imgwk" name="wknight" src="http://thumb1.shutterstock.com/thumb_small/98550/98550,1278941506,3/stock-photo-white-chess-knight-56993335.jpgg" />
</button>
</td>
<td id="a04" bgcolor="brown">
<button type="button" name="blabla">
<img class="imgwk" name="wknight" src="http://thumb1.shutterstock.com/thumb_small/98550/98550,1278941506,3/stock-photo-white-chess-knight-56993335.jpg" />
</button>
</td>
<td id="a05" bgcolor="brown">
<button type="button" name="blabla">
<img class="imgwk" name="wknight" src="http://thumb1.shutterstock.com/thumb_small/98550/98550,1278941506,3/stock-photo-white-chess-knight-56993335.jpg" />
</button>
</td>
<td id="a06" bgcolor="brown">
<button type="button" name="blabla">
<img class="imgwk" name="wknight" src="http://thumb1.shutterstock.com/thumb_small/98550/98550,1278941506,3/stock-photo-white-chess-knight-56993335.jpgg" />
</button>
</td>
<td id="a07" bgcolor="brown">
...
CSS
.imgwk {
height: 45px;
}
JavaScript
function getImgSrc(tableID, tdId) {
var table = document.getElementById(tableID),
tds = table.getElementsByTagName("td"),
img,
src;
Array.prototype.some.call(tds, function (td) {
if (td.id === tdId) {
img = td.getElementsByTagName("img");
if (img && img.length) {
src = img[0].src;
return true;
}
}
return false;
});
return src;
}
function setImgSrc(tableID, tdId, src) {
var table = document.getElementById(tableID),
tds = table.getElementsByTagName("td"),
img;
Array.prototype.some.call(tds, function (td) {
if (td.id === tdId) {
img = td.getElementsByTagName("img");
if (img && img.length) {
img[0].src = src;
return true;
}
}
return false;
});
return src;
}
alert(getImgSrc("table01", "a07"));
setImgSrc("table01", "a07", "http://img135.imageshack.us/img135/8067/daciathaliabe5.jpg");