Click to See Complete Forum and Search --> : Accessing a class with JavaScript.


AntonioMainenti
01-25-2003, 09:41 AM
<span class="a" onClick="doStuff(this.style);">Asdf.</span>

The 'doStuff()' function doesn't work, because unless I say what the style is in the span tag, it claims not to know anything about it. So I'm thinking there has to be some way to get to the class of the span with JavaScript.

Thanks, Alan.

khalidali63
01-25-2003, 09:52 AM
this.className

will get you the class name

cheers

Khalid

AntonioMainenti
01-25-2003, 10:22 AM
So if I wanted to get the 'top' property of the class, I would type...?

Vladdy
01-25-2003, 10:34 AM
Style attributes do not get populated when you assign class to an element. You can use currentStyle in IE or computedStyle in Gecko browsers, but a better way to access the values is from the styles collection.

khalidali63
01-25-2003, 11:27 AM
for that you should be able to do something like this

document.getElementById("id").style.property