1. Properties common to nodes
nodeName、nodeType、nodeValue
Examples:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>js_excise</title> <script src="./js/js_excise.js" type="text/javascript" charset="utf-8"></script> </head> <body style="height: 187.5rem;"> <button id="in" style="background-color: red;">更新</button> <input type="text" name="Text" placeholder="please your name" my='abner'> <script type="text/javascript"> var jsDiv = document.getElementById('in') console.log('属性节点:',jsDiv) console.log('nodeName:',jsDiv.nodeName) console.log('nodeType:',jsDiv.nodeType) console.log('nodeValue:',jsDiv.nodeValue) </script> </body> </html>
Output:
2. Node hierarchical relationship attributes
1> Get all the child nodes of the current element node
var childNodesArray = jsDiv.childNodes;
console.log(childNodesArray);
2> Get the first child node of the current element node
var firstchildNode = jsDiv.firstchild; console.log(firstchildNode);
3> Get the last child node of the current element node
var lastchildNode = jsDiv.lastchild;
console.log(lastchildNode);
4> Get the root node of the document of this node, equivalent to document
var rootNode = jsDiv.ownerDocument;
console.log (rootNode);
5> Get the parent node of the current node
var parentNode = jsDiv.parentNode;
console.log(parentNode);
6> Get the previous sibling node of the current node
var previousNode = jsDiv.previousSibling;
console.log(previousNode);
7> Get the next sibling node of the current node
var nextNode = jsDiv.nextSibling;
console.log(nextNode);
8> Get all attribute nodes of the current node
var jsInput = document.getElementById("put");
var allAttributesArry = jsInput.attributes;
console.log(allAttributesArray);