Skip to content
Advertisement

Is there a way to select sibling nodes?

For some performance reasons, I am trying to find a way to select only sibling nodes of the selected node.

For example,

JavaScript

If I selected inner1 node, is there a way for me to access its siblings, inner2-4 nodes?

Advertisement

Answer

Well… sure… just access the parent and then the children.

JavaScript

or… using jQuery:

JavaScript

Edit: Cletus as always is inspiring. I dug further. This is how jQuery gets siblings essentially:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement