Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can one select specific sibling of a context node using jQuery?

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;
like image 548
CW Holeman II Avatar asked Apr 02 '10 23:04

CW Holeman II


People also ask

How can I get next sibling in jQuery?

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.

What does siblings do in jQuery?

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.

How do I select something in jQuery?

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);


1 Answers

You can use .siblings() with a selector, like this:

$(myContextNode).siblings("span.myClass")
like image 63
Nick Craver Avatar answered Oct 31 '22 17:10

Nick Craver