Js nextSibling attributes and previussibling attributes overview and usage notes

Source: Internet
Author: User

1: nextSibling attributes
This attribute indicates the next node of the current node (the node after it belongs to the same level as the current node). If it does not have a node of the same level as it later, null is returned.
Note that the execution results of this attribute in different browsers are different. See the following example:
Let's look at an example:
Copy codeThe Code is as follows:
<Body>
<Div>
<Input id = "a4" type = "button" onclick = "alert (this. nextSibling);" value = "d"/>
<Input id = "a5" type = "button" onclick = "alert (this. nextSibling);" value = "e"/>
</Div>
</Bod

On the surface of the object structure, div's nextSibling has only two items-two input nodes. But there are actually five items --/n, input,/n, input,/n. This is because the input is used as the tag to create various form input controls, whether it is to generate buttons, checkbox, radio... or other form controls, IE will automatically create a 1-byte white space.
IE will skip the space document nodes generated between nodes (such as line breaks), but Mozilla will not -- FF will regard typographical elements such as space line breaks as node reads. Therefore, in ie, nextSibling is used to read the next node element. In FF, you need to write nextSibling. nextSibling.
Opera and safari process nextSibling in the same way as FF.

2: previussibling attributes
This attribute is opposite to the nextSibling attribute. For example, someTagObject. nextSibling. previussibling actually returns the label element, provided that the element must be followed by an element of the same level; otherwise, null is returned.

3: Attributes of HTML Tag Element objects obtained through nextSibling or previussibling
Generally, nextSibling is used first. nodeName to know its label name, or through nextSibling. nodeType to obtain the label type, and then, if the nextSibling. nodeName = # text, use nextSibling. nodeValue to obtain its text value; otherwise, you can use nextSibling. other common Tag Element attributes, such as innerHTML, are used to obtain their attributes.

Related Article

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.