1

I'm new to html/html5, just a question on properties of HTMLElement.

For example, HTMLInputElement has properties such as name, type, value, so I thought every available attributes is properties for an element, and of course class attribute should be a property since we can write:

<input class="XXX" type="submit" value="Submit"/>

but according to the link from MDN below, class is not a property for HTMLInputElement

https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement

we can see that class is not in the properties list.

So what kind of attributes can be considered as properties?

  • Because of compatibility to ECMAScript 3, where `class` was a (future) reserved word which couldn’t be a property name (it’s `className` instead). Same reason a ` – Sebastian Simon Oct 10 '19 at 12:54

1 Answers1

1

The MDN page for HTMLInputElement page has a section inheritance, which shows it as inheriting from HTMLElement which itself inherits from Element (and then Node, etc):

inheritance

Everything defined at the more abstract levels is available in the more concrete levels, and interface Element defines a property className which looks to be what you are after.

There is also the related property classList which in many cases is just as usable if not more.

Peter B
  • 22,460
  • 5
  • 32
  • 69