JS nextsibling Properties and PreviousSibling Properties Overview and usage notes

Source: Internet
Author: User

NextSibling Property: This property represents the next node of the current node, and if there is no node with its sibling, the Null;previoussibling property is returned: This property is the opposite of the NextSibling property, which is described in detail next, Interested in you may wish to know the next Oh, may be helpful to you 1:nextsibling Property This property represents the next node of the current node (the node that follows is the same level as the current node), or null if there are no nodes with its siblings.
It is important to note that this property does not perform the same results in different browsers, as shown in the following example:
Let's look at an example:
<div> </div>
<input id= "A4" type= "button" onclick= "alert (this.nextsibling);" value= "D"/>
<input id= "A5" type= "button" onclick= "alert (this.nextsibling);" value= "E"/>

On the structure surface of the object, the DIV's nextsibling has only 2 items--two input nodes. But there are actually 5 items of--/n,input,/n,input,/n. This is because input acts as a label for creating various form input controls, whether it is generating a button, a checkbox, a radio ... or other form controls, IE automatically creates a 1-byte space behind it.
IE will skip the space between nodes (e.g., newline characters), and Mozilla will not do this--ff the layout elements such as whitespace wrapping are treated as node reads, so the next node element can be read in IE using 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 has the opposite effect as the NextSibling property. For example: SomeTagObject.nextSibling.previousSibling actually returns the label element itself, but only if the tag element must have a sibling element behind it, or null is returned.

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

JS nextsibling Properties and PreviousSibling Properties Overview and usage notes

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.