Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-11-2009, 03:00 AM   PM User | #1
snl
New to the CF scene

 
Join Date: Oct 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
snl is an unknown quantity at this point
"random" link colors?

I have a div with a bunch of links. I'd like to specify a list of colors and then have the link list be randomly assigned the colors from the list. Can anyone help me with this? I've found scripts which will color all the links in the same random color upon reload, but I'd like all the links to be different colors. I hope this makes sense.
snl is offline   Reply With Quote
Old 10-14-2009, 10:24 PM   PM User | #2
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
Use the jquery selector to select all anchor tags, then change the CSS for each element, randomly assigning color.

Something like..

PHP Code:
$(function() {
    $(
"a").each(function (i) {
         $(
this).css("color",getRandomColor());
    });
});

function 
getRandomColor() {
//return a random color value

__________________

Last edited by Fumigator; 10-14-2009 at 10:27 PM.. Reason: corrected example
Fumigator is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:32 PM.


Advertisement
Log in to turn off these ads.