Notes when using JavaScript to retrieve the child node firstchild

Source: Internet
Author: User

The following is a very simple HTML code that looks the same at both ends:

{
This. style. display = 'none'; document. getelementbyid ('Code _ closed_text_110924 '). style. display = 'none'; document. getelementbyid ('Code _ open_image_110924 '). style. display = 'inline'; document. getelementbyid ('Code _ open_text_110924 '). style. display = 'inline ';
} "Id =" code_closed_image_110924 "style =" display: none "> {
This. style. display = 'none'; document. getelementbyid ('Code _ open_text_110924 '). style. display = 'none'; getelementbyid ('Code _ closed_image_110924 '). style. display = 'inline'; getelementbyid ('Code _ closed_text_110924 '). style. display = 'inline ';
} "Id =" code_open_image_110924 "> code
<Ul id = "mylist"> <li> 1 </LI>
<Li> 2 </LI>
<Li> 3 </LI>
<Li> 4 </LI>
<Li> 5 </LI>
<Li> 6 </LI>
</Ul>

 

{
This. style. display = 'none'; document. getelementbyid ('Code _ closed_text_110915 '). style. display = 'none'; document. getelementbyid ('Code _ open_image_110915 '). style. display = 'inline'; document. getelementbyid ('Code _ open_text_110915 '). style. display = 'inline ';
} "Id =" code_closed_image_110915 "style =" display: none "> {
This. style. display = 'none'; document. getelementbyid ('Code _ open_text_110915 '). style. display = 'none'; getelementbyid ('Code _ closed_image_110915 '). style. display = 'inline'; getelementbyid ('Code _ closed_text_110915 '). style. display = 'inline ';
} "Id =" code_open_image_110915 "> code
<Ul id = "mylist">
<Li> 1 </LI>
<Li> 2 </LI>
<Li> 3 </LI>
<Li> 4 </LI>
<Li> 5 </LI>
<Li> 6 </LI>
</Ul>

However, when we use

{
This. style. display = 'none'; document. getelementbyid ('Code _ closed_text_111031 '). style. display = 'none'; document. getelementbyid ('Code _ open_image_111031 '). style. display = 'inline'; document. getelementbyid ('Code _ open_text_111031 '). style. display = 'inline ';
} "Id =" code_closed_image_111031 "style =" display: none "> {
This. style. display = 'none'; document. getelementbyid ('Code _ open_text_111031 '). style. display = 'none'; getelementbyid ('Code _ closed_image_111031 '). style. display = 'inline'; getelementbyid ('Code _ closed_text_111031 '). style. display = 'inline ';
} "Id =" code_open_image_111031 "> code
VaR ou = Document. getelementbyid ("mylist ");
Alert (ou. firstchild. nodetype)

During the test, we found that:

In ie, the result is 1;

In ff, the first is: 1, and the second is 3;

This problem occurs because Firefox considers meaningless spaces and carriage returns as a text node.

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.