Whether it is getElementById or getElementsByTagName, when passing parameters, not all browsers must be case-sensitive, in order to prevent unnecessary errors and trouble, we must insist on a case-sensitive habit.
First, get the node by tag name
1, getElementsByTagName () method gets the node by the tag name, because the label name repeats, so it returns an array of objects htmlcollection (NodeList), which holds a list of all nodes of the same element name.
<script type= "Text/javascript" >window.onload=function () { if(document.getElementsByTagName) {//determine if getElementsByTagName is supported varLi = document.getElementsByTagName (' li ');//parameter passed in a tag name, passing in * means getting all the elementsAlert (LI);//returns a collection of arrays htmlcollectionalert (li.length);//returns the number of arraysAlert (li[0]);//htmlhtmlelement Node object, here is the first Li tagAlert (Li.item (0));//Ibid . //Gets the node object so that it can get the content through the node object, etc. propertiesAlert (li[0].tagname); Alert (li[0].innerhtml); }Else{alert ("Browser not compatible, please replace") } };</script>2, through the wildcard character to get the HTML tag element, IE browser when using wildcards, the document will be the beginning of the HTML specification declaration as the first element node. Firefox's Firebug will count as one, and it's not okay to turn it off.
<script type= "Text/javascript" >window.onload=function () { if(document.getElementsByTagName) {//determine if getElementsByTagName is supported varLi = document.getElementsByTagName (' * ');//parameter passed in a tag name, passing in * means getting all the elementsAlert (LI);//returns a collection of arrays htmlcollectionalert (li.length);//returns the number of arraysAlert (li[0]);//returns the first Htmlhtmlelement node objectAlert (Li.item (0));//Ibid .alert (li[0].tagname);//The first element in IE browser is the declaration of a document!}Else{alert ("Browser not compatible, please replace") } };</script>
3, get the Body node object, because there can be only one body node object in an HTML document, so you can get:
function () { if(document.getelementsbytagname) { // Determines whether getElementsByTagName is supported var body = document.getelementsbytagname (' body ') [0]; // if no addition [0] returns an array, plus [0] returns the Body node object alert (body); } Else { alert ("Browser is incompatible, please replace") } };
4, you can also first get the ID through getElementById, and then through Getelementbytagname get this ID under the specified element, rather than get the whole document of that element
JavaScript Dom_ Gets the element method _getelementsbytagname () Gets the node list of the same element