Reputation: 57
Trying to make a image based button that will change a image on the page
Here is the code I have
<script type="text/javascript">
function nextimg()
{
alert("clicked")
document.getElementById("image").src="images/gallery/gallery-2.jpg";
}
</script>
<div class="gallery">
<table>
<tr>
<td><img src="images/lt_arrow_dark.png"/></td>
<td><img id="image" src="images/gallery/gallery-1.jpg"/></td>
<td><img onclick="nextimg()" src="images/rt_arrow_dark.png" height="55" width="24"/></td>
</tr>
</table>
</div>
Nothing happens when I click on the image. Any Ideas? Thanks
Upvotes: 2
Views: 5391
Reputation: 4559
<script type="text/javascript">
windown.onload = function() {
function nextimg() {
alert("clicked")
document.getElementById("image").src="images/gallery/gallery-2.jpg";
}
}
</script>
Upvotes: 0
Reputation: 340
Adding the Javascript into head and the other part of the code into body, enveloped in HTML got it to work for me on Chrome and IE.
Upvotes: 0
Reputation: 28665
You need to remove the z-index
of -2 in your css.
.gallery {
background-color:#090909;
position:relative;
top:60px;
width:100%;
}
Upvotes: 0
Reputation: 56
I copied your code verbatim into a HTML file on my machine and it pops up the "clicked!" alert in both Chrome and Firefox. Are you sure you don't have JavaScript disabled or something? What browser are you using?
Upvotes: 1