Jquery Siblings
jQuery Traversing - Siblings
With jQuery y'all tin traverse sideways inwards the DOM tree to honour siblings of an element.
Siblings percentage the same parent.
Traversing Sideways inwards The DOM Tree
There are many useful jQuery methods for traversing sideways inwards the DOM tree:- siblings()
- next()
- nextAll()
- nextUntil()
- prev()
- prevAll()
- prevUntil()
jQuery siblings() Method
The siblings() method returns all sibling elements of the selected element.The next event returns all sibling elements of <h2>:
Example
$(document).ready(function(){
$("h2").siblings();
});
The next event returns all sibling elements of <h2> that are <p> elements:
Example
$(document).ready(function(){
$("h2").siblings("p");
});
jQuery next() Method
The next() method returns the side yesteryear side sibling chemical component subdivision of the selected element.The next event returns the side yesteryear side sibling of <h2>:
Example
$(document).ready(function(){
$("h2").next();
});
jQuery nextAll() Method
The nextAll() method returns all side yesteryear side sibling elements of the selected element.The next event returns all side yesteryear side sibling elements of <h2>:
Example
$(document).ready(function(){
$("h2").nextAll();
});
jQuery nextUntil() Method
The nextUntil() method returns all side yesteryear side sibling elements betwixt 2 given arguments.The next event returns all sibling elements betwixt a <h2> together with a <h6> element:
Example
$(document).ready(function(){
$("h2").nextUntil("h6");
});
Comments
Post a Comment