nosepilot
Technical User
- Oct 21, 2010
- 3
I found javascript to toggle an image between 2 sources:
I've got a page with 5 images I'd like to toggle.
I've been trying to edit the javascript so it can handle 5 images.
I haven't gotten far.
Is there a simpler way to do this?
This is my code:
<script type="text/javascript">
function changeIt()
{
var x = document.example.src.split("/");
var t = x.length-1;
var y = x[t];
if(y=='jj.gif')
{
document.example.src='1.gif'
}
if(y=='1.gif')
{
document.example.src='jj.gif'
}
}
</script>
<img src='jj.gif' name='example' onclick="changeIt()">
<img src='jj.gif' name='example2' >
<img src='jj.gif' name='example3' >
<img src='jj.gif' name='example4' >
<img src='jj.gif' name='example5' >
I've got a page with 5 images I'd like to toggle.
I've been trying to edit the javascript so it can handle 5 images.
I haven't gotten far.
Is there a simpler way to do this?
This is my code:
<script type="text/javascript">
function changeIt()
{
var x = document.example.src.split("/");
var t = x.length-1;
var y = x[t];
if(y=='jj.gif')
{
document.example.src='1.gif'
}
if(y=='1.gif')
{
document.example.src='jj.gif'
}
}
</script>
<img src='jj.gif' name='example' onclick="changeIt()">
<img src='jj.gif' name='example2' >
<img src='jj.gif' name='example3' >
<img src='jj.gif' name='example4' >
<img src='jj.gif' name='example5' >