Link to home
Start Free TrialLog in
Avatar of suroma
suromaFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Javascript change background image of div

My javascript seems to work Ok with the text changing fine and the background image seems to be changed (it shows me the correct path in the alert) but the image does not show. Help!
<script type="text/javascript">
        function changeDivImage(ImageURL,ImageText) {
            document.getElementById('desc').innerHTML = ImageText;
            document.getElementById('headerimage').style.backgroundImage = 'url(' + ImageURL + ')';
            alert( document.getElementById('headerimage').style.backgroundImage)
        }
 
    </script>
 
CALLED FROM
 
                    <ul>
                        <li id="liOne" class="one"><a href="#" onclick="javascript:changeDivImage('../images/headerbantham.jpg','Bantham,Devon')"><img src="images/1x1.gif" height="20px" width="20px" alt="" style="padding:0; margin:0;" /></a></li>
                        <li id="liTwo" class="two"><a href="#" onclick="javascript:changeDivImage('../images/headertorquay.jpg','Torquay,Devon')"><img src="images/1x1.gif" height="20px" width="20px" alt="" /></a></li>
</ul>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of suroma
suroma
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial