Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

changing class of a <span> element with JavaScript

I am trying to change the class of a element with Javascript using the below code:

parent.document.getElementById('<?php echo $markid ?>').class = 'unlistened';

Not having much luck though. How do I do this properly?

like image 841
ian Avatar asked Jul 09 '09 13:07

ian


2 Answers

.className rather than .class

like image 135
Justin Wignall Avatar answered Oct 01 '22 16:10

Justin Wignall


Use .className instead of .class

Class is a reserved word in JS so it's changed to className. A few other HTML attributes are changed in a similar way. "for" changes to "htmlFor" for instance.

like image 21
edeverett Avatar answered Oct 01 '22 18:10

edeverett