By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,165 Members | 849 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,165 IT Pros & Developers. It's quick & easy.

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

P: 20
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
May 4 '08 #1
Share this Question
Share on Google+
7 Replies


hsriat
Expert 100+
P: 1,654
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.
May 5 '08 #2

acoder
Expert Mod 15k+
P: 16,027
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.
May 5 '08 #3

P: 20
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
May 6 '08 #4

P: 20
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!
May 6 '08 #5

hsriat
Expert 100+
P: 1,654
match() should work...

Just before you compare both of them, do alert() for them. ie.
Expand|Select|Wrap|Line Numbers
  1. alert('Present location:'+location.href);
  2. alert('Link location:'+a.href);
  3. //where a is referance of the link (important)
And then see why are you not able to get what yo want to do.
May 6 '08 #6

P: 20
match() should work...

Just before you compare both of them, do alert() for them. ie.
Expand|Select|Wrap|Line Numbers
  1. alert('Present location:'+location.href);
  2. alert('Link location:'+a.href);
  3. //where a is referance of the link (important)
And then see why are you not able to get what yo want to do.

that worked!!!!
thank you so much :)
May 6 '08 #7

hsriat
Expert 100+
P: 1,654
that worked!!!!
thank you so much :)
You are welcome.
Glad to know you got it working :)
May 6 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.