Javascript-Setting background image of a DIV via a function and function
parameter
I have the following HTML:
<div id="tab1" style="position:relative;
background-image:url(buttons/off.png);
<a href="javascript:ChangeBackgroundImageOfTab('tab1', 'on');">
<img id="DivBtn1" name="DivBtn1" src="buttons/text.png" >
</a>
</div>
and the following Javascript:
function ChangeBackgroungImageOfTab(tabName, imagePrefix)
{
document.getElementById(tabName).style.background-image=
'url("buttons/" + imagePrefix + ".png")';
}
The issue arises when i try to set the tabs background image via a call to
getElementByID - I do now know how to create a dynamic URL that uses the
parameter that was passed in, along with some other hard coded values. In
this case, we are swapping the OFF background image with the ON background
image.
How can i do this? Is there some way to use a javascript variable, assign
the full path to it, then send it into the call as the background image
path?
No comments:
Post a Comment