473,387 Members | 1,650 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,387 software developers and data experts.

Change Link Colour With Javascript

I have a little problem. I have a menu with a set of links, one of which has to be a different colour to the others. I know this can be done manually but I'm using a CMS system that doesn't allow this, so I'm trying to change it with Javascript, to no avail. The closest I've come to a solution is this script for Invision Power Board, but I can't customise it.

Expand|Select|Wrap|Line Numbers
  1. <script>//New PM Flasher - By Markup
  2. userLinks=document.getElementById('userlinks');
  3. if(userLinks.innerHTML.match("Inbox"))
  4. {
  5. newMsg=false;
  6. a=userLinks.getElementsByTagName("A");
  7. for(i=0;i<a.length;i++)if(a[i].innerHTML.match(/Inbox\s\([0-9]+\)/)&&a[i].innerHTML.match(/[0-9]+/)>0)newMsg=i;
  8. if(newMsg)
  9. {
  10. inbox=a[newMsg];
  11. inbox.style.fontWeight="Bold";
  12. inbox.style.color="Red";
  13. }
  14. }
  15.  
  16. </script>
  17.  
Any ideas anyone?
Nov 5 '07 #1
7 1586
acoder
16,027 Expert Mod 8TB
Post the code for the links.
Nov 5 '07 #2
If there are two links, both the same colour and I want one different, for example:

[HTML]
<table width="100%" border="0" cellpadding="0" cellspacing="0" id="mainmenu">
<tr align="left">
<td>
<a href="index.php?option=com_frontpage&amp;Itemid=1" class="mainlevel">home</a>
</td>
</tr>
<tr align="left">
<td>
<a href="index.php?option=com_content&amp;task=view&a mp;id=12&amp;Itemid=26" class="mainlevel">why train with us?</a>
</td>
</tr>
</table>
[/HTML]

I'm trying to apply a version of the code I posted above to these links, so that, for example, the second link would change colour when the document loads through my javascript.
Nov 5 '07 #3
acoder
16,027 Expert Mod 8TB
How are you determining which link is the one whose colour you're changing?
Nov 5 '07 #4
How are you determining which link is the one whose colour you're changing?
That's my problem my friend, the code in my first post is just an example. I was trying to use something similar to the code I posted.

So I have two links for example, one "home" and one "about us" (this is just an example). Both links are white but I need the "about us" link to be red. I need the Javascript to search my page at run time for the "about us" link, and if it finds the link, it'll change the colour. Unfortunately I don't know how to tell the Javascript to find this particular link as it doesn't have it's own ID. This is why I was trying to use the code I showed in my first post.
Nov 6 '07 #5
acoder
16,027 Expert Mod 8TB
Try:
Expand|Select|Wrap|Line Numbers
  1. var links = document.getElementsByTagName("a");
  2. for (i = 0; i < links.length; i++) {
  3.   if (links[i].innerHTML == "about us") links[i].style.color = "red";
  4. }
Nov 6 '07 #6
Thanks for your help, I managed to get a solution similar to this.
Nov 7 '07 #7
acoder
16,027 Expert Mod 8TB
Glad to see that you got it working. Post again if you have more questions.
Nov 7 '07 #8

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

Similar topics

9
by: michael | last post by:
I have many links on a page, but for example sake, these two: <a href="bla1.html" id="link1">bla1</a> <a href="bla1.html" id="link2">bla1</a> I use a Javascript function to change the link...
4
by: Dwight | last post by:
I need to change the colour of text values within a table. For example "Software" being red, "Lab Software" blue etc. To change colour of number values simply, 1, entered into the format section...
7
by: garyusenet | last post by:
I'm using krypton toolkit which has allowed me to make a cool looking form. However, when I set my textbox to disabled it is 'greyed' out. The grey colour isn't in keeping with the office 2007...
1
by: maheshgupta0248 | last post by:
Hi All, I have created a dialog based application in vc++ which includes some buttons.I want to give different colours for their borders and also for the text on them.Can u pls provide solution for...
2
by: srkssit | last post by:
I have bought a new Image Rating script developped by Cresoft. The script is working superb in my Application but as being a non-technical person I am not able to change the colour of the menu.Can...
6
by: gavy7210 | last post by:
hello i am using struts 1.2,Eclipse Platform Version: 3.4.2,mySql 5.0.1,jdk 1.5.. i have a login form(jsp) in which a user logs in,in case he doesnt enter his username and/or password an error...
0
by: Dataflashsabot | last post by:
Title says it all, really: Can you change the colour of a RichTextBox's cursor?
4
by: neelsfer | last post by:
I have specific medicines in a table consisting of about 3000 records, that cause problems when its captured at stocktake every year. My question - can i change the colour of these spedific...
0
by: Sushil Mishra | last post by:
Hi guys, I'm new to Visual basic. M using vb studio 2010. started it today. Learnt to build a notepad using rich text box.Now i want to change the colour of specific words/syntax as soon as they...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.