본문 바로가기

JAVASCRIPT

DOM Element Object

HTML DOM Nodes

In the HTML DOM (Document Object Model), everything is a node:

  • The document itself is a document node
  • All HTML elements are element nodes
  • All HTML attributes are attribute nodes
  • Text inside HTML elements are text nodes
  • Comments are comment nodes

The Element Object

In the HTML DOM, the Element object represents an HTML element.

Element objects can have child nodes of type element nodes, text nodes, or comment nodes.

NodeList object represents a list of nodes, like an HTML element's collection of child nodes.

Elements can also have attributes. Attributes are attribute nodes (See next chapter).


Browser Support

Object
ElementYesYesYesYesYes
NodeListYesYesYesYesYes

The Element Object and the NodeList Object is supported in all major browsers.


Properties and Methods

The following properties and methods can be used on all HTML elements:

Property / MethodDescription
element.accessKeySets or returns the accesskey attribute of an element
element.addEventListener()Attaches an event handler to the specified element
element.appendChild()Adds a new child node, to an element, as the last child node
element.attributesReturns a NamedNodeMap of an element's attributes
element.blur()Removes focus from an element
element.childElementCountReturns the number of child elements an element has
element.childNodesReturns a collection of an element's child nodes (including text and comment nodes)
element.childrenReturns a collection of an element's child element (excluding text and comment nodes)
element.classNameSets or returns the value of the class attribute of an element
element.click()Simulates a mouse-click on an element
element.clientHeightReturns the height of an element, including padding
element.clientLeftReturns the width of the left border of an element
element.clientTopReturns the width of the top border of an element
element.clientWidthReturns the width of an element, including padding
element.cloneNode()Clones an element
element.compareDocumentPosition()Compares the document position of two elements
element.contains()Returns true if a node is a descendant of a node, othwerwise false
element.contentEditableSets or returns whether the content of an element is editable or not
element.dirSets or returns the value of the dir attribute of an element
element.firstChildReturns the first child node of an element
element.firstElementChildReturns the first child element of an element
element.focus()Gives focus to an element
element.getAttribute()Returns the specified attribute value of an element node
element.getAttributeNode()Returns the specified attribute node
element.getElementsByClassName()Returns a collection of all child elements with the specified class name
element.getElementsByTagName()Returns a collection of all child elements with the specified tag name
element.getFeature()Returns an object which implements the APIs of a specified feature
element.hasAttribute()Returns true if an element has the specified attribute, otherwise false
element.hasAttributes()Returns true if an element has any attributes, otherwise false
element.hasChildNodes()Returns true if an element has any child nodes, otherwise false
element.idSets or returns the value of the id attribute of an element
element.innerHTMLSets or returns the content of an element
element.insertBefore()Inserts a new child node before a specified, existing, child node
element.isContentEditableReturns true if the content of an element is editable, otherwise false
element.isDefaultNamespace()Returns true if a specified namespaceURI is the default, otherwise false
element.isEqualNode()Checks if two elements are equal
element.isSameNode()Checks if two elements are the same node
element.isSupported()Returns true if a specified feature is supported on the element
element.langSets or returns the value of the lang attribute of an element
element.lastChildReturns the last child node of an element
element.lastElementChildReturns the last child element of an element
element.namespaceURIReturns the namespace URI of an element
element.nextSiblingReturns the next node at the same node tree level
element.nextElementSiblingReturns the next element at the same node tree level
element.nodeNameReturns the name of a node
element.nodeTypeReturns the node type of a node
element.nodeValueSets or returns the value of a node
element.normalize()Joins adjacent text nodes and removes empty text nodes in an element
element.offsetHeightReturns the height of an element, including padding, border and scrollbar
element.offsetWidthReturns the width of an element, including padding, border and scrollbar
element.offsetLeftReturns the horizontal offset position of an element
element.offsetParentReturns the offset container of an element
element.offsetTopReturns the vertical offset position of an element
element.ownerDocumentReturns the root element (document object) for an element
element.parentNodeReturns the parent node of an element
element.parentElementReturns the parent element node of an element
element.previousSiblingReturns the previous node at the same node tree level
element.previousElementSiblingReturns the previous element at the same node tree level
element.querySelector()Returns the first child element that matches a specified CSS selector(s) of an element
element.querySelectorAll()Returns all child elements that matches a specified CSS selector(s) of an element
element.removeAttribute()Removes a specified attribute from an element
element.removeAttributeNode()Removes a specified attribute node, and returns the removed node
element.removeChild()Removes a child node from an element
element.replaceChild()Replaces a child node in an element
element.removeEventListener()Removes an event handler that has been attached with the addEventListener() method
element.scrollHeightReturns the entire height of an element, including padding
element.scrollLeftSets or returns the number of pixels an element's content is scrolled horizontally
element.scrollTopSets or returns the number of pixels an element's content is scrolled vertically
element.scrollWidthReturns the entire width of an element, including padding
element.setAttribute()Sets or changes the specified attribute, to the specified value
element.setAttributeNode()Sets or changes the specified attribute node
element.styleSets or returns the value of the style attribute of an element
element.tabIndexSets or returns the value of the tabindex attribute of an element
element.tagNameReturns the tag name of an element
element.textContentSets or returns the textual content of a node and its descendants
element.titleSets or returns the value of the title attribute of an element
element.toString()Converts an element to a string
  
nodelist.item()Returns the node at the specified index in a NodeList
nodelist.lengthReturns the number of nodes in a NodeList


'JAVASCRIPT' 카테고리의 다른 글

DOM Attribute Object  (0) 2014.12.18
DOM Document Object  (0) 2014.12.18
DOM Event Object Reference  (0) 2014.12.18
DOM  (0) 2014.12.18
디지탈 시계  (0) 2014.09.22