Jquery traversing siblings

jquery provide number of methods for traversing sideways in the dom tree.

  • jquery sibling method
  • jquery next method
  • jquery nextAll method
  • jquery pre method
  • jquery preAll method

jquery siblings() method

the jquery .siblings() method get the siblings of each element in the set of matched elements.

the jquery sibling method syntax :-

(selector).siblings (selector )
parameterdescription
selectorrequired. specifies a selector to match elements against.

the jquery sibling method example


jquery next() method

the jquery .next() method get the immediately following sibling of each element in the set of matched elements.if a selector is provided, it retrieves the next sibling only if it matched that selector.

the jquery next method syntax :-

(selector).next (selector )
parameterdescription
selectorrequired. specifies a selector to match elements against.

The jquery next method example


jquery nextall() method

the jquery .nextall() method get all following siblings of each element in the set of matched elements.

the jquery nextall method syntax:-

  $ (selector).nextall (selector )
parameterdescription
selectorrequired. specifies a selector to match elements against.

the jquery nextall method example


jquery prev() method

the jquery .prev() method get the immediately preceding sibling of each element in the set of matched elements.

the jquery pre method syntax :-

             $ (selector).prev (selector )
parameterdescription
selectorrequired. specifies a selector to match elements against.

The jquery pre method example


jquery prevall() method

the jquery .prevall() method get preceding siblings of each element in the set of matched elements.

the jquery pre method syntax :-

(selector).prevall (selector )
parameterdescription
selectorrequired. specifies a selector to match elements against.

The jquery preall method example