SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Sep 2008
    Posts
    341
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JavaScript changing class name

    I have an element which is hidden by using a CSS class named 'hide' (simply display:none).

    I want to be able to display this using JS (by removing the display:none).

    I need to change the class, but also ensure other classes (if applicable) aren't removed from that element (so it doesn't just replace a 'show' class with all other classes).

    I know that document.get.ElementById('element-id').class doesn't do anything.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by johnsmith153 View Post
    I need to change the class, but also ensure other classes (if applicable) aren't removed from that element (so it doesn't just replace a 'show' class with all other classes).
    The hasClass, addClass, and removeClass functions will let you achieve that.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Addict
    Join Date
    Sep 2008
    Posts
    341
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perfect. Thanks.


Bookmarks

Posting Permissions

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