ie in JS getElementsByTagName cannot get element bugs

Source: Internet
Author: User

ie in JS getElementsByTagName cannot get element bugs

Definitions and usage
The getElementsByTagName () method returns a collection of objects with the specified label name.

Grammar
document.getElementsByTagName (tagname) description
The order in which the getElementsByTagName () method returns elements is the order in which they are in the document.

If you pass the special string "*" to the getElementsByTagName () method, it returns a list of all the elements in the document, and the order in which they are arranged is the order in which they are in the document.
Tips and comments
Note: Strings passed to the getElementsByTagName () method can be case-insensitive.

For more details please see: http://www.111cn.net/wy/js-ajax/getelementsbytagname.htm


Click Input[id=test]

IE6/7: Throwing anomalies

IE8/9: Pop-up undefined

Firefox/safari/chrome/opera: Eject [object Htmlinputelement]

When the statement 1 and statement 2 positions are exchanged, they are not reproduced.

When the div.getelementsbytagname is replaced by div.childnodes[0] or div.children[0], it does not reappear.

Preliminary judgment is the implementation of getElementsByTagName in IE, found in the MSDN section:

<!doctype html>
    <meta charset= "Utf-8"
getElementsByTagName cannot get element bug</title> in     <title>ie;
<body>
<input type= "button" id= "Test" value= "test"
<script>
 var html= ' <input type= ' CheckBox ">";
 var div = document.createelement ("div");
 div.innerhtml = html;
 
 var a = div.getelementsbytagname ("input");//Statement 1
 document.body.appendchild (div);//Statement 2
 
 document.getelementbyid ("test"). onclick = function () {
  alert (a[0));
 } ;
</script>
</body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.