Methods of js document object: addEventListener(), adoptNode(node), close(), createAttribute(), open(), write(), writeln(), renameNode(), etc.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
Document object
Every HTML document loaded into the browser will become a Document object.
The Document object allows us to access all elements in the HTML page from scripts.
Tip: The Document object is part of the Window object and can be accessed through the window.document property.
Methods of Document object
Method | Description |
---|---|
addEventListener() | Add a handle to the document |
adoptNode(node) | Returns an adapted node from another document to the current document. |
close() | Closes the output stream opened with the document.open() method and displays the selected data. |
createAttribute() | Create an attribute node |
createDocumentFragment() | Create an empty DocumentFragment object and returns this object. |
createElement() | Create element node. |
createTextNode() | Create a text node. |
getElementsByClassName() | Returns a collection of all elements with the specified class name in the document as a NodeList object. |
getElementById() | Returns a reference to the first object with the specified id. |
getElementsByName() | Returns a collection of objects with the specified name. |
getElementsByTagName() | Returns a collection of objects with the specified tag name. |
importNode() | Copy a node from another document to this document for application. |
normalize() | Delete empty text nodes and connect adjacent nodes |
normalizeDocument() | Remove empty text nodes and connect adjacent nodes' |
open() | Open a stream to collect data from any document.write() or document. The output of the writeln() method. |
querySelector() | Returns the first element in the document that matches the specified CSS selector |
querySelectorAll() | document.querySelectorAll() is a new method introduced in HTML5, which returns a list of all element nodes that match the CSS selector in the document |
removeEventListener() | Remove the event handler in the document (added by the addEventListener() method) |
renameNode() | Rename the element or attribute node. |
write() | Write HTML expression or JavaScript code to the document. |
writeln() | Identical to the write() method, except that a newline character is written after each expression. |
[Related recommendations: javascript learning tutorial]
The above is the detailed content of What are the methods of javascript document object. For more information, please follow other related articles on the PHP Chinese website!