SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    change the div's background

    i want change the div's background on click event
    i try with:
    onclick="document.getElementById('menu_eventi').style.backgroundImage='url(interfaccia/menu_eventi_over.gif)'

    But it not works.
    Why

  2. #2
    SitePoint Guru Rob_D's Avatar
    Join Date
    Oct 2006
    Location
    UK
    Posts
    882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should put a double quote at the end.

    Otherwise send us the code.

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The double quote there is.The code is:
    <div id="menu_eventi" style="float:left;height:27px;width:75px;background-image: url(interfaccia/menu_eventi_clicked.gif);background-position: bottom;" onclick="document.getElementById('menu_eventi').style.backgroundImage='url(interfaccia/menu_eventi_normal.gif)';"></div>

  4. #4
    SitePoint Guru Rob_D's Avatar
    Join Date
    Oct 2006
    Location
    UK
    Posts
    882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What are you clicking on?

  5. #5
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    on div

  6. #6
    SitePoint Guru Rob_D's Avatar
    Join Date
    Oct 2006
    Location
    UK
    Posts
    882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try something like this:

    HTML Code:
    <html>
    <head>
    <style type="text/css">
    #menu_eventi {
    display:block;
    width:100px;
    height:100px;
    }
    </style>
    <script language="javascript">
    function change() {
    document.getElementById('menu_eventi').style.backgroundImage='url(interfaccia/menu_eventi_over.gif)';
    return false;
    }
    </script>
    </head>
    <body>
    <div id="menu_eventi" onclick="change();">Click here</div>
    </body>
    </html>


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
  •