ll55 ll55 - 7 days ago 6
HTML Question

Album - td's onclick is not changing image src with its function

(Finally,) I almost finished writing an album code for my blog. But when I was testing it, the

onclick
function of
td
tag broke.

<td class="null right" onclick="next();return false;">
/*The next function is to change image to next one*/


I clicked on that
td
, the middle image should be changed but it wasn't. Is there something wrong in the code?

https://jsfiddle.net/7oafsf0u/

Answer

working fine. maybe some problem in snippet.

and i recommend to use tbody tag.

var myImage= new Array(); 
myImage[0]="http://cdn.akamai.steamstatic.com/steam/apps/271590/ss_80b965d66b13d6eb5e1468151a371e12fe159663.600x338.jpg";       
myImage[1]="http://cdn.akamai.steamstatic.com/steam/apps/271590/ss_be2b9e45c671f95b8bc9fde58dbbd1154b0b633a.600x338.jpg";
myImage[2]="http://cdn.akamai.steamstatic.com/steam/apps/271590/ss_3da42391c6317205177248dea0a48ced89998a8d.600x338.jpg";
myImage[3]="http://cdn.akamai.steamstatic.com/steam/apps/271590/ss_bb2ee3b9b48a60857873192cfff10546e01d4a86.600x338.jpg";

var count = 0;

function next(){
count++;
document.getElementById("album").src = myImage[count];
}
.album {
  vertical-align: middle;
  text-align: center;
  width: 100%;
}
.album-table td {
  vertical-align: middle;
  overflow: hidden;
}
.album-table td:hover {
  background-color: #E0F1FF;
}
.arrow {
  width: 40px;
  height: 40px;
  vertical-align: middle;
}
.left {
  border-top-left-radius: 50px;
  border-bottom-left-radius: 50px;
}
.right {
  border-top-right-radius: 50px;
  border-bottom-right-radius: 50px;
}
.left:hover, .right:hover {
  cursor: pointer; cursor: hand;
  background-color: #CEE9FF;
}
<table class="album-table">

<tr><td class="null left">
<img class="arrow" src="http://i.imgur.com/2q4MZDO.png" />
</td>
<td class="null">
<img id="album" class="album" src="http://cdn.akamai.steamstatic.com/steam/apps/271590/ss_80b965d66b13d6eb5e1468151a371e12fe159663.600x338.jpg" />
</td>
<td class="null right" onclick="next()">
<img class="arrow" src="http://i.imgur.com/D0Wt0OJ.png" />
</td></tr>

</table>

Comments