Hi, I have just joined the forum and I need help with Javascrip dropdown menus. I have written a function which should change the background image of a button when it is clicked:
function change(el)
{
if (el.style.backg round='url(arro w-up-title2.jpg)'){
el.style.backgr ound='url(arrow-down-title2.jpg)'
}
if (el.style.backg round='url(arro w-down-title2.jpg)'){
el.style.backgr ound='url(arrow-up-title2.jpg)'
}
}
The problem is the background only changes once. When I click on the main menu the background is originally arrow-down-title2.jpg and this changes to arrow-up-title2.jpg but when I click the menu again it does not change back to arrow-down-title2.jpg.
Does anyone have an idea why?
This is how I pass my parameter:
<div id="menu" onclick="change (this);SwitchMe nu('sub1')">Men u</div>
function change(el)
{
if (el.style.backg round='url(arro w-up-title2.jpg)'){
el.style.backgr ound='url(arrow-down-title2.jpg)'
}
if (el.style.backg round='url(arro w-down-title2.jpg)'){
el.style.backgr ound='url(arrow-up-title2.jpg)'
}
}
The problem is the background only changes once. When I click on the main menu the background is originally arrow-down-title2.jpg and this changes to arrow-up-title2.jpg but when I click the menu again it does not change back to arrow-down-title2.jpg.
Does anyone have an idea why?
This is how I pass my parameter:
<div id="menu" onclick="change (this);SwitchMe nu('sub1')">Men u</div>
Comment