Some help with dropdown menus

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • angelinahmaleka
    New Member
    • Mar 2008
    • 3

    Some help with dropdown menus

    Hi, I have just joined the forum and I need help with Javascrip dropdown menus. I have written a function which should change the background image of a button when it is clicked:

    function change(el)
    {

    if (el.style.backg round='url(arro w-up-title2.jpg)'){
    el.style.backgr ound='url(arrow-down-title2.jpg)'
    }

    if (el.style.backg round='url(arro w-down-title2.jpg)'){
    el.style.backgr ound='url(arrow-up-title2.jpg)'
    }


    }


    The problem is the background only changes once. When I click on the main menu the background is originally arrow-down-title2.jpg and this changes to arrow-up-title2.jpg but when I click the menu again it does not change back to arrow-down-title2.jpg.

    Does anyone have an idea why?

    This is how I pass my parameter:

    <div id="menu" onclick="change (this);SwitchMe nu('sub1')">Men u</div>
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Question moved to Javascript forum.

    Comment

    • hsriat
      Recognized Expert Top Contributor
      • Jan 2008
      • 1653

      #3
      [code=javascript]
      var bg = 0;
      function change(el) {
      el.style.backgr ound = bg ? 'url(arrow-down-title2.jpg)' : 'url(arrow-up-title2.jpg)';
      bg = !bg;
      }[/code]

      Comment

      • angelinahmaleka
        New Member
        • Mar 2008
        • 3

        #4
        Originally posted by hsriat
        [code=javascript]
        var bg = 0;
        function change(el) {
        el.style.backgr ound = bg ? 'url(arrow-down-title2.jpg)' : 'url(arrow-up-title2.jpg)';
        bg = !bg;
        }[/code]
        Wow, it works. Thank you so much !!!!!!!!!!!!!!! !!!!!!!!!!!!

        Comment

        Working...