0

(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/

dda
  • 6,030
  • 2
  • 25
  • 34
Louis55
  • 408
  • 6
  • 17
  • Put js in body (before closing body tag) - check 'javascript' button, 'load type' section, in fiddle: https://jsfiddle.net/7oafsf0u/3/ – sinisake Nov 27 '16 at 07:25
  • @nevermind, that works but what is the difference between 'onLoad' and 'no wrap in body'? Can I put the js in 'head'? – Louis55 Nov 27 '16 at 07:30
  • http://stackoverflow.com/questions/5468350/javascript-not-running-on-jsfiddle-net – sinisake Nov 27 '16 at 07:36

1 Answers1

0

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>
Mahi
  • 1,707
  • 11
  • 22