How can one select a specific sibling of a context node using jQuery? Specifically, given context node myContextNode
select the sibling span
with class myClass
.
document.evaluate("../span[@class='myClass']",
myContextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).
singleNodeValue;
jQuery next() Method The next() method returns the next sibling element of the selected element. Sibling elements are elements that share the same parent. The DOM tree: This method traverse forward along the next sibling of DOM elements.
The siblings() is an inbuilt method in jQuery which is used to find all siblings elements of the selected element. The siblings are those having same parent element in DOM Tree.
The select() method is an inbuilt method in jQuery which is used when some letters or words are selected (or marked) in a text area or a text field. Syntax: $(selector). select(function);
You can use .siblings()
with a selector, like this:
$(myContextNode).siblings("span.myClass")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With