SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Evangelist artcoder's Avatar
    Join Date
    Aug 2005
    Location
    Planet Earth
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Change background image

    I have a background-image attached to a div as in ...

    Code:
    <div id="test_div1" style="width: 15px; height:15px; background-image:url(icon1.png);">
    &nbsp;
    </div>
    What javascript I can use to dynamically change the background image from icon1.png to icon2.png?

  2. #2
    SitePoint Zealot coothead's Avatar
    Join Date
    Jan 2005
    Location
    Chertsey, London, England
    Posts
    164
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi there artcoder,

    I do not recommend the use of inline css or javascript but as this is the the way that you have asked the question....
    Code:
    <div id="test_div1" style="width: 15px; height:15px; background-image:url(icon1.png);"
       onmouseover="this.style.backgroundImage='url(icon2.png)'"
       onmouseout="this.style.backgroundImage='url(icon1.png)'">
    </div>
    coothead


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •