Web Design Web Design Forum
Registration is free! Here you can view your subscribed threads, work with private messages and edit your profile and preferences Calendar Find other members Frequently Asked Questions Search
Home Web Design

Convenient web based access to our favorite web design Usenet groups

web design reviews

This is Interesting: Free Magazines for Graphics designers and webmasters  





  Last Thread  Next Thread
Author
Thread Post New Thread   

Easy change link colors on page w/out reload
 

michael




quote this post edit post

IP Loged report this post

Old Post  06-23-04 - 12:22 AM  
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 colors:

document.getElementById("link1").style.color='lime'
document.getElementById("link2").style.color='lime'

Above works fine to change the 2 link colors to lime, but is there way to
dynamically change all links on a page, without a separate id for each
link, and without reloading the page with a new link style declaration?



Post Follow-Up to this message ]
Re: Easy change link colors on page w/out reload
 

Harlan Messinger




quote this post edit post

IP Loged report this post

Old Post  06-23-04 - 12:22 AM  
"michael" <nomail@example.com> wrote in message
news:cb9ma4$2i4$01$1@news.t-online.com...
> 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 colors:
>
> document.getElementById("link1").style.color='lime'
> document.getElementById("link2").style.color='lime'
>
> Above works fine to change the 2 link colors to lime, but is there way to
> dynamically change all links on a page, without a separate id for each
> link, and without reloading the page with a new link style declaration?
>

var links = document.getElementsByTagName("a");



Post Follow-Up to this message ]
Re: Easy change link colors on page w/out reload
 

michael




quote this post edit post

IP Loged report this post

Old Post  06-23-04 - 12:22 AM  
Harlan Messinger wrote:

> var links = document.getElementsByTagName("a");

By the above I've got the variable "links" as an HTML object collection.
I suppose this is now a Javascript question; but how could I dynamically
change all link colors on the page from here?
Any further pointers would be much appreciated... Thanks.




Post Follow-Up to this message ]
Re: Easy change link colors on page w/out reload
 

Mr.Clean




quote this post edit post

IP Loged report this post

Old Post  06-23-04 - 12:22 AM  
In article <cb9pgn$4to$05$1@news.t-online.com>, nomail@example.com
says...
> Harlan Messinger wrote:
> 
>
> By the above I've got the variable "links" as an HTML object collection.
> I suppose this is now a Javascript question; but how could I dynamically
> change all link colors on the page from here?
> Any further pointers would be much appreciated... Thanks.
>
>
>
Use a for loop on the collection.


Post Follow-Up to this message ]
Re: Easy change link colors on page w/out reload
 

michael




quote this post edit post

IP Loged report this post

Old Post  06-23-04 - 12:22 AM  
> Use a for loop on the collection.

Does anyone have an example?



Post Follow-Up to this message ]
Re: Easy change link colors on page w/out reload
 

michael




quote this post edit post

IP Loged report this post

Old Post  06-23-04 - 12:22 AM  
> Does anyone have an example?

... found a solution:

links = document.getElementsByTagName("a");
for (var i=0;i<links.length;i++)
if (links[i].className=="link")
links[i].style.color = 'lime';
}




Post Follow-Up to this message ]
Re: Easy change link colors on page w/out reload
 

Jan Roland Eriksson




quote this post edit post

IP Loged report this post

Old Post  06-23-04 - 12:23 AM  
On Tue, 22 Jun 2004 18:13:43 +0200, michael <nomail@example.com> wrote:

>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 colors:

Why?

--
Rex



Post Follow-Up to this message ]
Re: Easy change link colors on page w/out reload
 

michael




quote this post edit post

IP Loged report this post

Old Post  06-23-04 - 09:15 AM  
> Why?

Why not?


Post Follow-Up to this message ]
Re: Easy change link colors on page w/out reload
 

Neal




quote this post edit post

IP Loged report this post

Old Post  06-23-04 - 09:15 AM  
On Wed, 23 Jun 2004 07:51:05 +0200, michael <nomail@example.com> wrote:
 
>
> Why not?


For starters, not all users have Javascript enabled. You can change link
colors in CSS, which is more widely trusted.


Post Follow-Up to this message ]
Re: Easy change link colors on page w/out reload
 

Brian




quote this post edit post

IP Loged report this post

Old Post  06-28-04 - 12:16 AM  
michael wrote:
 
>
> Does anyone have an example?

Please take it to comp.lang.javascript. But before posting a question,
check the archives. This has come up before. You might also consider
Google.

--
Brian (remove ".invalid" to email me)
http://www.tsmchughs.com/


Post Follow-Up to this message ]
Sponsored Links
 





All times are GMT. The time now is 04:18 AM. Post New Thread   
  Previous Last Thread   Next Thread next
Stylesheets archive | Show Printable Version | Email this Page | Subscribe to this Thread

Popular forums

Adobe Photoshop forum Macromedia Flash Web Site Design
Dreamweaver FrontPage forum
JavaScript Forum XML forum
Style Sheets VRML
Forum Jump:
Rate This Thread:

 

XML RSS Feed web design latest articles Syndicate our forum via XML or simple JavaScript

Web Design archive  Database administration help  


Top Home  -  Register  -  Control Panel   -  Memberlist  -  Calendar  -  Faq  -  Search Top