[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1719
  • Last Modified:

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

0
suroma
Asked:
suroma
1 Solution
 
suromaAuthor Commented:
Changed it to .background and it now works....
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now