SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: remove class

  1. #1
    SitePoint Wizard
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    remove class

    Does anyone know how to remove a class from an element.

    leftclicker.className.replace('disabled',' ');

    but this doesn't work.

    thanks


  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)
    Maybe
    Code:
    leftclicker.removeAttribute('class');

  3. #3
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by elduderino View Post
    Does anyone know how to remove a class from an element.

    leftclicker.className.replace('disabled',' ');

    but this doesn't work.
    Did you assign that? Try:
    Code:
    leftclicker.className = leftclicker.className.replace(/\s*\bdisabled\b/,'');
    Tab-indentation is a crime against humanity.

  4. #4
    SitePoint Wizard
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi guys,

    I did this in the end. Yes my problam was that I hadn't assigned it:

    rightclicker.className = rightclicker.className.replace('disabled',' ');

    what is the regex going logic ali?

  5. #5
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe:

    Code JavaScript:
    function removeClass(elem,class) {
      return elem.className = elem.className.replace( new RegExp('(^|\\s)' + class + '(\\s|$)') ,' ');
    }
     
    removeClass(leftclicker,'disabled');
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  6. #6
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by elduderino View Post
    what is the regex going logic ali?
    The regex caters for multiple classes within a single element.
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)


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
  •