Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
159
rated 0 times [  165] [ 6]  / answers: 1 / hits: 21154  / 10 Years ago, mon, august 18, 2014, 12:00:00

I have a radio button, and when it is pressed a function is called, which accepts the class of the button as an argument. So something like this:



<input class=myclass type=radio name=name value=x checked=true onClick=myFunction(this.value, this.getAttribute('class'))></input>


Notice that in my onClick, I have this.getAttribute('class') instead of simply this.class. I tried using this.class but I kept getting undefined. Is this.class not an acceptable thing to do? I have used this.id elsewhere in my code which works fine, but for some reason I need to use getAttribute when I want to reference class.



So essentially I am asking what is the difference between this.class and this.getAttribute('class')?


More From » html

 Answers
39

Use className to get the current value of the class attribute. I think the reason behind this is because class is a reserved word.


[#69744] Thursday, August 14, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
neildrews

Total Points: 166
Total Questions: 103
Total Answers: 85

Location: Moldova
Member since Sat, Aug 6, 2022
2 Years ago
;