-
屬性
-
attributes
- 返回元素的屬性集合. (DOM Core)(No IE)
- childNodes
- 返回包含當前元素的子元素的列表. (DOM Core)
- className
- 獲取/設置元素的類別. (HTML, XUL, ...)
- clientHeight
- 元素內部的高度. (HTML-specific)
- clientLeft
- The width of the left border of an element in pixels. 不被普遍的支持. (HTML-specific)
- clientTop
- The width of the top border of an element in pixels. 不被普遍的支持. (HTML-specific)
- clientWidth
- 元素內部的寬度. (HTML-specific)
- dir
- 獲取/設置元素的方向. (HTML, XUL)
- firstChild
- 返回當前元素第一個子元素. (DOM Core)
- id
- 獲取/設置元素的id. (HTML, XUL, ...)
- innerHTML
- 獲取/設置元素內部的HTML標記和內容. (HTML-specific)
- lang
- 指定元素的屬性值和文本內容的語言. (HTML-specific)
- lastChild
- 返回當前元素最后一個子元素.(DOM Core)
- length
- 返回列表內元素的數量.(例如:childNodes). (DOM Core, not part of
Element
interface)
- localName
- Returns the local part of the qualified name of this node. (DOM Core)
- name
- 獲取/設置元素的name屬性—并非所有此屬性. (HTML-specific)
- namespaceURI
- 節點的命名空間 URI, 如果沒有指定則為
null
. (DOM Core)
- nextSibling
- 返回節點的下一個兄弟節點. (DOM Core)
- nodeName
- 返回節點的名稱. (DOM Core)
- nodeType
- 返回節點的類型. (DOM Core)
- nodeValue
- 返回節點的值. (DOM Core)
- offsetHeight
- 返回元素的高度相對布局. (HTML-specific)
- offsetLeft
- 獲取元素的左邊界到它的
offsetParent
節點的左邊界的水平距離(單位像素). (HTML-specific)
- offsetParent
- Returns a reference to the object in which the current element is offset (i.e., the parent element). (HTML-specific)
- offsetTop
- 獲取元素的上邊界到它的
offsetParent
節點的上邊界的垂直距離(單位像素). (HTML-specific)
- offsetWidth
- 返回元素的寬度相對布局. (HTML-specific)
- ownerDocument
- 返回元素所在的document對像. (DOM Core)
- parentNode
- 返回元素的父親節點. (DOM Core)
- prefix
- 返回當前元素的命名空間前綴, 如果未指定則返回
null
. (DOM Core)
- previousSibling
- Returns the node immediately previous to the given one in the tree. (DOM Core)
- scrollHeight
- Returns the height of the scroll view of an element. (HTML-specific)
- scrollLeft
- Gets or sets the number of pixels that an element's content is scrolled to the left. (HTML-specific)
- scrollTop
- Gets/sets the distance between the top of an element and the topmost portion of its content currently visible. (HTML-specific)
- scrollWidth
- Returns the width of the scroll view of an element. (HTML-specific)
- style
- Returns an object representing the declarations in the the element's style attribute. (HTML, XUL, ...)
- tabIndex
- 獲取/設置元素的TAB次序. (HTML)
- tagName
- 返回元素的標簽名稱. (DOM Core)
- textContent
- Gets/sets the text content of an element including its descendants. (DOM Core)
方法
- addEventListener
- Allows the registration of event listeners on the event target. (DOM Events)
- appendChild
- Inserts the specified node into the list of nodes on the current document. (DOM Core)
- blur
- 將鍵盤焦點從當前元素上移開. (HTML, XUL)
- click
- 在當前元素上模擬一次單擊. (HTML, XUL)
- cloneNode
- Returns a duplicate of the current node. (DOM Core)
- dispatchEvent
- Allows the dispatch of events into the implementation's event model. (DOM Events)
- focus
- 使當前元素獲得焦點. (HTML, XUL)
- getAttribute
- 返回當前節點中指定屬性的值. (DOM Core)
- getAttributeNS
- Returns the value of the attribute with the given name and namespace. (DOM Core)
- getAttributeNode
- Returns the attribute of the element as a separate node. (DOM Core)
- getAttributeNodeNS
- A namespace-aware version of
getAttributeNode
(DOM Core)
- getElementsByTagName
- Returns the elements of a particular tag name that are descendants of the current element. (DOM Core)
- hasAttribute
- Returns a boolean value indicating whether the element has the specified attribute or not. (DOM Core)
- hasAttributeNS
- Returns a boolean value indicating whether the element has an attribute with the specified name and namespace. (DOM Core)
- hasAttributes
- Returns a boolean value indicating whether the element has any attributes. (DOM Core)
- hasChildNodes
- Returns boolean value indicating whether the current element has children or not. (DOM Core)
- insertBefore
- Inserts a node before the current element in the DOM. (DOM Core)
- item
- Retrieves a node from a
NodeList
by index. (DOM Core, not part of the Element
interface)
- normalize
- Puts the node and all of its subtree into a "normalized" form. (DOM Core)
- removeAttribute
- Removes an attribute from the element. (DOM Core)
- removeAttributeNS
- Removes the attribute with specified name and namespace from the element. (DOM Core)
- removeAttributeNode
- Removes the specified attribute from the element. (DOM Core)
- removeChild
- Removes a child node from the current element. (DOM Core)
- removeEventListener
- Removes an event listener from the element. (DOM Events)
- replaceChild
- Replaces one child node on the current element with another. (DOM Core)
- scrollIntoView
- Scrolls the page until the element gets into the view. (HTML)
- setAttribute
- Adds a new attribute or changes the value of an existing attribute on the current element. (DOM Core)
- setAttributeNS
- Adds a new attribute or changes the value of an attribute with the given namespace and name. (DOM Core)
- setAttributeNode
- Adds a new attribute node to the current element. (DOM Core)
- setAttributeNodeNS
- Adds a new attribute node with the specified namespace and name. (DOM Core)
- supports
- Tests if this DOM implementation supports a particular feature.
事件句柄
對應HTML中的 'onxxx' 事件, 有一些相應的屬性.
不像其他的屬性, 這些屬性是一些函數 (或其他實現了 EventListener 接口的對象) 而不是字符串. 事實上, 在HTML里分配一個事件就創建一個指定代碼的函數包裝. 比如以下的HTML代碼:
<div onclick="foo();">點我!</div>
假設 element
是指向這一個 div
的引用, 那么 element.onclick
相當于下面的效果:
function onclick(event) {
foo();
}
Note how the event object is passed as parameter event
to this wrapper function.
- onblur
- Returns the event handling code for the blur event.
- onclick
- Returns the event handling code for the click event.
- ondblclick
- Returns the event handling code for the dblclick event.
- onfocus
- Returns the event handling code for the focus event.
- onkeydown
- Returns the event handling code for the keydown event.
- onkeypress
- Returns the event handling code for the keypress event.
- onkeyup
- Returns the event handling code for the keyup event.
- onmousedown
- Returns the event handling code for the mousedown event.
- onmousemove
- Returns the event handling code for the mousemove event.
- onmouseout
- Returns the event handling code for the mouseout event.
- onmouseover
- Returns the event handling code for the mouseover event.
- onmouseup
- Returns the event handling code for the mouseup event.
- onresize
- Returns the event handling code for the resize event.