Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    snl
    snl is offline
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    "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.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    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 11:27 PM. Reason: corrected example


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •