Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Senior Member james's Avatar
    Join Date
    May 2003
    Location
    Melbourne, AUSTRALIA
    Posts
    364
    Member #
    1352
    Is it possible to change the CSS class of an element with JavaScript?
    In last month's competition jraven used document.getElementById('ElemID') to change an elements contents (just add .innerHTML = ...), its src or href, and you can use it to change CSS properties, like backgroundcolor or anything else.

    What I want to do is change an element's class, so I can change a table row from class='InactiveRow' to class='ActiveRow'.

    That means I can make lots of changes to it, like bgcolor, font etc, in one line. Otherwise one line for each change.

    Thanks,
    James.

    I've attached jraven's latest(?) entry.
    James H
    Home Page · Mars Page · www.fihsf1.net (formerly www·fihs·net)

  2.  

  3. #2
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    document.getElementById('elemID').className = 'newClassName';

  4. #3
    Senior Member james's Avatar
    Join Date
    May 2003
    Location
    Melbourne, AUSTRALIA
    Posts
    364
    Member #
    1352
    I tested it and it works. Thanks.
    James H
    Home Page · Mars Page · www.fihsf1.net (formerly www·fihs·net)


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 09:00 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2020 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com