Hi,
I'm not big on Javascript, it's kind of on the periphary of what I do but I've had need to knock up a simple rollover script for a current job.
It doesn't need to be particularly portable but I would like to easily be able to add/remove buttons without messing with the javascript. Apologies in advance for any horrible coding faux pas I've made![Smile :) :)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
Now to the problem...
The script is meant to swap out a few images by altering the src attribute. More specifically changing the src from say,
btn_about.png to on_btn_about.png
This seems to work fine in Firefox and Safari but doesn't work in IE (windows).
When I rollover one of the buttons, the src changes but it just changes to "on_" rather than "on_btn_about.png"
Any ideas why?
<honk>*:O)</honk>
Foamcow Heavy Industries - Web site design in Cheltenham and Gloucester
Earl & Thompson Marketing - Marketing Agency Services in Gloucestershire
I'm not big on Javascript, it's kind of on the periphary of what I do but I've had need to knock up a simple rollover script for a current job.
It doesn't need to be particularly portable but I would like to easily be able to add/remove buttons without messing with the javascript. Apologies in advance for any horrible coding faux pas I've made
Code:
window.onload=function(){
var nav = document.getElementById('nav');
var buttons = nav.getElementsByTagName('IMG');
for(var i=0; i<buttons.length; i++){
buttons[i].onmouseover = function(){
var original = this.getAttribute('src');
var original = original.split('/');
this.setAttribute('src','images/' + 'on_' + original[1]);
}
buttons[i].onmouseout = function(){
var original = this.getAttribute('src');
var original = original.split('_');
this.setAttribute('src','images/btn_' + original[2]);
}
}
}
Now to the problem...
The script is meant to swap out a few images by altering the src attribute. More specifically changing the src from say,
btn_about.png to on_btn_about.png
This seems to work fine in Firefox and Safari but doesn't work in IE (windows).
When I rollover one of the buttons, the src changes but it just changes to "on_" rather than "on_btn_about.png"
Any ideas why?
<honk>*:O)</honk>
Foamcow Heavy Industries - Web site design in Cheltenham and Gloucester
Earl & Thompson Marketing - Marketing Agency Services in Gloucestershire