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.
Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18
  1. #16
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    947
    Thanks
    0
    Thanked 130 Times in 129 Posts
    Code:
    var bgClasses = ['bg-orange', 'bg-black', 'bg-none', 'bg-green', 'bg-blue',
                                 'bg-brown', 'bg-white', 'bg-yellow', 'bg-purple'];
    
    var tableCells = document.getElementsByTagName('td');
    var usedClasses=['bg-Special'];
    while (usedClasses.length<tableCells.length){
    usedClasses=usedClasses.concat(shuffle(bgClasses)); //extend usedClasses with bgClasses until long enough
    }
    usedClasses.splice(tableCells.length); // make tableCells and UsedClasses the same length
    usedClasses=shuffle(usedClasses);
    the while loop makes it support any number of table cells and classes.
    and .concat(shuffle(bgClasses)) makes it random which classes is cut off in case (tableCells.length % bgClasses.length) != 1
    Last edited by Lerura; 07-22-2014 at 01:11 AM.

  2. #17
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,596
    Thanks
    80
    Thanked 4,633 Times in 4,595 Posts
    Yep. Thus proving, once again, that their are more ways than one to remove the epidermis of any program, be the creator feline or not.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  3. #18
    New Coder
    Join Date
    Aug 2009
    Location
    public_html/cgi-bin/
    Posts
    91
    Thanks
    14
    Thanked 1 Time in 1 Post
    I can't thank the both of you enough for your kind contributions.

    I'm only a skint student at the mo, but if I had spare change I would certainly be buying you both a coffee at least! You've helped me big time.

    Ended up using Lerura's code, purely because I seemed to understand it a little quicker than Old Pedants. Plus I had made another change to the app, which meant Lerura's was a little easier to modify accordingly.

    All working now, this problem turned out to be a little more awkward than I had anticipated!

    Thank you again.

    Kind Regards
    Owen Ayres


 
Page 2 of 2 FirstFirst 12

Posting Permissions

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