473,394 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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

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
7 1446
hsriat
1,654 Expert 1GB
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
16,027 Expert Mod 8TB
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
theoni
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
theoni
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
1,654 Expert 1GB
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
theoni
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
1,654 Expert 1GB
that worked!!!!
thank you so much :)
You are welcome.
Glad to know you got it working :)
May 6 '08 #8

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

Similar topics

4
by: JesusFreak | last post by:
From: us_traveller@yahoo.com (JesusFreak) Newsgroups: microsoft.public.scripting.jscript Subject: toolbar script problem NNTP-Posting-Host: 192.92.126.136 Recently, I downloaded the following...
1
by: ajay | last post by:
I have following code for a slide menu but i twiked it to work for a single level menu. Open it in a Browser to get a clear picture. I have 2 Qs 1) How to make first entry as non-link. i.e i...
2
by: RWD | last post by:
I am trying to figure out how to change the target frame in my hyperlink on a DHTML menu. The menu is in one frame and the target frame is called "main" The code is below: Thanks in advance...
4
by: Yuk Cheng | last post by:
<<<start index.htm>>> <html> <head> <script> function perform(action){ } </script> </head>
2
by: Jackson Yap | last post by:
can someone kind enough to help me look at the attached html and js file? Why is it that the javascript menu could not work at www.apchosting.net but could work at...
0
by: =?Utf-8?B?SmltSGVhdmV5?= | last post by:
I have created an ASP:Menu which is Horizontal and has dynamic menu items. If I move my cursor to one of the static menu selections and click on it (which should cause nothing to happen), my screen...
4
by: stuckagain | last post by:
Hi, I have a page with a scrollable DIV, and within that DIV, I have a few asp.net menu controls. The idea being, the user mouses over the small icons and is presented with a list of options. ...
1
omerbutt
by: omerbutt | last post by:
hi every one i have a menu li and ul based the problem is when any specific category in the li is hovered the li or the sub-cat items appear but as i move my mouse over the sub-cat or level two li it...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.