2 replies [Last post]
Jenni
Jenni's picture
Offline
Enthusiast
Seattle
Last seen: 11 years 43 weeks ago
Seattle
Joined: 2007-03-09
Posts: 115
Points: 0

I have a link that I'd like to assign a new css class style to on mouse click. I tried this, but it doesn't work

People

Notice the code that says 'this.style.class=cur01'. This doesn't do anything. I know the CSS class "cur01" is valid because when I assign the class='cur01' property to the element, it accepts it allright.

Thanks,

-- jenni

Tyssen
Tyssen's picture
Offline
Moderator
Brisbane
Last seen: 6 years 13 weeks ago
Brisbane
Timezone: GMT+10
Joined: 2004-05-01
Posts: 8201
Points: 1386

It's because class is not a

It's because class is not a style property. You can do:

this.style.color
this.style.background
this.style.font-size

etc, but not class. I think (not that good on js) that you need this.className=... instead.

How to get help
Post a link. If you can't post a link, jsFiddle it.
My blog | My older articles | CSS Reference

Jenni
Jenni's picture
Offline
Enthusiast
Seattle
Last seen: 11 years 43 weeks ago
Seattle
Joined: 2007-03-09
Posts: 115
Points: 0

ah, ok. You're right. I had

ah, ok. You're right. I had to use javascript, but it worked just fine.

this.className='cur01';

This did the trick.

Thanks!