JS nextsibling Properties and PreviousSibling Properties Overview and use of attention _ basics

Source: Internet
Author: User
1:nextsibling Property
The attribute represents the next node of the current node (the following node is at the same level as the current node), or null if there is no subsequent node with its sibling.
A special note is that the results of this property are not identical in different browsers, as shown in the following example:
Let's take a look at an example:
Copy Code code 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 structure surface of the object, the DIV's nextsibling has only 2 entries-two input nodes. But there are actually 5 items of--/n,input,/n,input,/n. This is because input is the label that creates various form input controls, whether it is generating a button, a checkbox, a radio ... or other form controls, IE automatically creates a 1-byte bit of white space later.
IE will skip the space document nodes (such as newline characters) that are generated between the nodes, and Mozilla will not do so--FF will read the typographic elements such as the space-wrapping as node reads, so the next node element can be read in IE with nextsibling. This is what you need to write in FF: nextsibling.nextsibling.
Opera and Safari treat nextsibling in the same way as FF

2:previoussibling Property
This property is just the opposite of the NextSibling property. For example: SomeTagObject.nextSibling.previousSibling actually returns the label element itself, but the prerequisite must be that the label element must have a sibling element behind it, or it will return null.

3: Attributes of HTML tag element objects obtained via nextsibling or previoussibling
It is generally through nextsibling.nodename to know its label name, or through Nextsibling.nodetype to know its label type, then, if the Nextsibling.nodename = #text, The text value is learned by Nextsibling.nodevalue, otherwise, the properties of other common tag element properties such as nextsibling.innerhtml can be obtained.

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.