YouTip LogoYouTip

Htmldom Properties

# HTML DOM Properties * * * Properties are values of nodes (HTML elements) that you can get or set. * * * ## Programming Interface The HTML DOM can be accessed via JavaScript (and other programming languages). All HTML elements are defined as objects, and the programming interface is the object's methods and properties. Methods are actions you can perform (like add or modify elements). Properties are values you can get or set (like the name or content of a node). * * * ## The innerHTML Property The simplest way to get the content of an element is by using the innerHTML property. The innerHTML property is useful for getting or replacing the content of HTML elements. ## Example The following code gets the innerHTML of the

element with id="intro": ## Example

Hello World!

var txt=document.getElementById("intro").innerHTML; document.write(txt); [Try it Yourself Β»](#) In the example above, getElementById is a method, while innerHTML is a property. | ![Image 2: lamp](#) | The innerHTML property can be used to get or change any HTML element, including and . | | --- | * * * The nodeName property specifies the name of a node. * nodeName is read-only * The nodeName of element nodes is the same as the tag name * The nodeName of attribute nodes is the same as the attribute name * The nodeName of text nodes is always #text * The nodeName of the document node is always #document **Note:** nodeName always contains the uppercase tag name of the HTML element. * * * ## The nodeValue Property The nodeValue property specifies the value of a node. * The nodeValue for element nodes is undefined or null * The nodeValue for text nodes is the text itself * The nodeValue for attribute nodes is the attribute value * * * ## Getting Element Values The following example retrieves the text node value of the

tag: ## Example

Hello World!

x=document.getElementById("intro"); document.write(x.firstChild.nodeValue); [Try it Yourself Β»](#) * * * ## The nodeType Property The nodeType property returns the type of a node. nodeType is read-only. The most important node types are: | Element Type | NodeType | | --- | --- | | Element | 1 | | Attribute | 2 | | Text | 3 | | Comment | 8 | | Document | 9 |
← Func CdateHtmldom Methods β†’