gets the name “as HTML": all tags become tags, so we see the bold name.
2 The second
gets the name “as text”, so we literally see Winnie-the-Pooh!
In most cases, we expect the text from a user, and want to treat it as text. We don't want unexpected HTML in our
site. An assignment to textContent does exactly that.
The “
The *hidden' attribute and the DOM property specifies whether the element is visible or not.
\den” property
‘We can use it in HTML or assign it using JavaScript, like this:
With the attribute "hidden"
JavaScript assigned the property "hidden"
Technically, hidden works the same as style="display:none” . But it’s shorter to write
Here's a blinking element
(HTMLAnchorElement ).
+ id —the value of “id” attribute, for all elements (HTMLELement ).
+ .and much more.
For instance:
Most standard HTML attributes have the corresponding DOM property, and we can access it like that.
If we want to know the full list of supported properties for @ given class, we can find them in the specification. For
instance, HTMLInput€lement: is documented at [Link] spec [Link]/#htmlinputelement.
Or if we'd like to get them fast or are interested in a concrete browser specification ~ we can always output the
element using [Link](elem) and read the properties. Or explore "DOM properties" in the Elements tab
of the browser developer tools
Summary
Each DOM node belongs to a certain class. The classes form a hierarchy. The full set of properties and methods
come as the result of inheritance.
Main DOM node properties are:
nodeType
We can use it to see if a node is a text or an element node. It has a numeric value: 1 for elements, 3 for text
nodes, and a few others for other node types. Read-only
nodeName/tagname
For elements, tag name (uppercased unless XML-mode). For non-element nodes nodeName describes what itis.
Read-only.
innerHT™L,
The HTML content of the element. Can be modified,
outerHT™L‘The full HTML of the element. A write operation into elem. outerHTML does not touch elem itself. Instead it
gets replaced with the new HTML in the outer context.
nodeValue/data
The content of a non-element node (text, comment). These two are almost the same, usually we use data . Can
be modified
textContent
The text inside the element: HTML minus all . Writing into it puts the text inside the element, with all
special characters and tags treated exactly as text. Can safely insert user-generated text and protect from
unwanted HTML insertions.
hidden
When set to true, does the same as CSS display:none
DOM nodes also have other properties depending on their lass. For instance, elements
(HTMLInputElement ) support value, type, while elements (HTMLANchorElement ) support href etc
Most standard HTML attributes have a corresponding DOM property.
However, HTML attributes and DOM properties are not always the same, as we'll see in the next chapter.