Make currently loaded menu item appear in different style than other menu items

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • theoni
    New Member
    • Feb 2008
    • 20

    Make currently loaded menu item appear in different style than other menu items

    Hello,

    I am making a javascript menu and I want to make the menu item that is currently loaded appear with different style than the other menu items. This can only be fixed in the javascript code loaded before the page so I tried to compare the location.href with the href value of the menu item and load different styles when href==location. href

    this doesn't work even though i tried hard so i guess i am missing something. If you know how I am supposed to compare href (the value of the menu item) to location.href and changes styles please help me because I am really upset with that.


    Thank you for your help
    Theoni
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    Don't compare with a == operator. Use match() instead, and compare only the keyword instead of the whole url.

    But I think it would be better if you do that in server side script (or your HTML file). It can be easily implemented there.

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      Please remember to provide a meaningful Title for any threads started (see the FAQ entry Use a Good Thread Title).

      This helps to ensure that other members, and also the general public, will have a better chance of finding answers to any similar questions. Thanks!

      Moderator.

      Comment

      • theoni
        New Member
        • Feb 2008
        • 20

        #4
        Originally posted by acoder
        Please remember to provide a meaningful Title for any threads started (see the FAQ entry Use a Good Thread Title).

        This helps to ensure that other members, and also the general public, will have a better chance of finding answers to any similar questions. Thanks!

        Moderator.
        I am sorry I was upset when i wrote the post and couldn't come up with a better heading.. will be be more cautious from now on

        Comment

        • theoni
          New Member
          • Feb 2008
          • 20

          #5
          Originally posted by hsriat
          Don't compare with a == operator. Use match() instead, and compare only the keyword instead of the whole url.

          But I think it would be better if you do that in server side script (or your HTML file). It can be easily implemented there.
          Unfortunately there is no way give the style on the server side. That is impossible the way the menu is implemented... I tried to use match() but that didn't work right either :( Will try harder later, thank you for the tip though!

          Comment

          • hsriat
            Recognized Expert Top Contributor
            • Jan 2008
            • 1653

            #6
            match() should work...

            Just before you compare both of them, do alert() for them. ie.[code=javascript]
            alert('Present location:'+loca tion.href);
            alert('Link location:'+a.hr ef);
            //where a is referance of the link (important)[/code]
            And then see why are you not able to get what yo want to do.

            Comment

            • theoni
              New Member
              • Feb 2008
              • 20

              #7
              Originally posted by hsriat
              match() should work...

              Just before you compare both of them, do alert() for them. ie.[code=javascript]
              alert('Present location:'+loca tion.href);
              alert('Link location:'+a.hr ef);
              //where a is referance of the link (important)[/code]
              And then see why are you not able to get what yo want to do.

              that worked!!!!
              thank you so much :)

              Comment

              • hsriat
                Recognized Expert Top Contributor
                • Jan 2008
                • 1653

                #8
                Originally posted by theoni
                that worked!!!!
                thank you so much :)
                You are welcome.
                Glad to know you got it working :)

                Comment

                Working...