DOM is the Document Object Model: the purpose of DOM creation is to reconstruct the entire HTML page and add, change, or rearrange projects on the page. Look at the simplest html file: & amp; lt; html & amp; gt; & amp; lt; head & amp; gt; & amp; l
DOM is the Document Object Model: the purpose of DOM creation is to reconstruct the entire HTML page and add, change, or rearrange projects on the page.
Look at the simplest html file:
DOM
Hello phpddt.com
Hello world!
Let's see:
Clearly, there is only one root node., Which has two subnodes:AndIn the same way, there are subnodes!
Since you want to refactor the html page, you have to get the node value. How can you get the node value?
(1) getElementById () and getElementsByTagName () getElementsByName ()
The getElementById () method returns a reference to the first object with the specified ID. Note that a value is returned.
The getElementsByTagName () method returns a set of objects with the specified tag name. Note that an array is returned.
The getElementsByName () method returns a set of objects with the specified name. It mainly returns an array, which can be seen from the s behind the Element!
This method is similar to the getElementById () method, but it queries the name attribute of an element rather than the id attribute.
You can fully understand the following example:
Test it by yourself. You can easily see the differences between the three!
Php point-through-www.phpddt.com Script function getId () {$ val = document. getElementById ("myId"); alert ($ val. innerHTML);} function getName () {var x = document. getElementsByName ("myInput"); alert (x. length);} function getTagName () {var x = document. getElementsByTagName ("input"); alert (x. length);} script This is a demonstration of the getElementById method.
(2) Use parentNode, firstChild, and lastChild to perform "short-distance travel" in the document ".
Untitled Document