Агуулга
- DOM Nodes
- Node Relationships
- DOM Lesson one
- and has one child: "DOM Lesson one" has one child: "Hello world!" and are siblings Navigating Between Nodes You can use the following node properties to navigate between nodes with JavaScript: parentNode childNodes[nodenumber] firstChild lastChild nextSibling previousSibling Child Nodes and Node Values A common error in DOM processing is to expect an element node to contain text. Example: DOM Tutorial The element node (in the example above) does not contain text. It contains a text node with the value "DOM Tutorial". The value of the text node can be accessed by the node's innerHTML property: var myTitle = document.getElementById("demo").innerHTML; Accessing the innerHTML property is the same as accessing the nodeValue of the first child: var myTitle = document.getElementById("demo").firstChild.nodeValue; Accessing the first child can also be done like this: var myTitle = document.getElementById("demo").childNodes[0].nodeValue; All the (3) following examples retrieves the text of an element and copies it into a element: Example My First Page
- My First Page
- My First Page
- My First Page
- My First Page
- W3Schools