Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript and the DOM (Retiring) Making Changes to the DOM Changing Element Attributes

Jason Welsh
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jason Welsh
Treehouse Project Reviewer

Why does input.class not return "description"?

If typing input.type in the console returns the value, "text", why does typing input.class not return "description", since that is the value of that attribute, and the attribute is just a property of the input object?

3 Answers

Kevin Korte
Kevin Korte
28,149 Points

If one was to look up the spec here: https://developer.mozilla.org/en-US/docs/Web/API/Element/className there is a note that states,

The name className is used for this property instead of class because of conflicts with the "class" keyword in many languages which are used to manipulate the DOM.

ywang04
ywang04
6,762 Points

You can use getAttribute function to get the class name, which is mentioned in this video as well.

input.getAttribute('class');    //the result is "description".
Jason Welsh
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jason Welsh
Treehouse Project Reviewer

Thanks for the reply. That is interesting. What other languages are typically used to manipulate the DOM? Are any a viable option for replacing JS in the future?