SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2002
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Changing a class with JS

    on mousing over a cell I want to change the class associated with it, how might I do this...
    the closest I've come is:

    onMouseOver="this.style.class='myclass';"

    needless to say it doesn't work...

    any suggestions?

  2. #2
    SitePoint Zealot
    Join Date
    Sep 1999
    Location
    North America
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try something like:

    this.className=...

    instead. Class is not an attribute of STYLE.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2002
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nice one

    cheers

  4. #4
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It couldn't work round that way - could it.

    The style of an object is determined partially by it's class - hence if the class was a property of a style - then it'd be changing itself before being implemented.

    so yes - it's a direct property of the object - and it's called className.
    Most info like this can be easily found at msdn.microsoft.com/library

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  5. #5
    SitePoint Zealot
    Join Date
    Sep 1999
    Location
    North America
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Flawless_koder
    It couldn't work round that way - could it.

    The style of an object is determined partially by it's class - hence if the class was a property of a style - then it'd be changing itself before being implemented.

    so yes - it's a direct property of the object - and it's called className.
    Most info like this can be easily found at msdn.microsoft.com/library

    Flawless
    It's interesting though that we use "className" to reference the "class" attribute. Seems to go against how most attributes are accessed in JavaScript/DHTML, simply by its identical name in HTML.


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
  •