Loading Please Wait...
With jQuery you can traverse sideways in the DOM tree to find siblings of an element. Siblings share the same parent.
There are many useful jQuery methods for traversing sideways in the DOM tree:
The jQuery siblings() method returns all sibling elements of the selected element.
The following example returns all sibling elements of <h2>:
$(document).ready(function(){
$("h2").siblings();
});
You can also use an optional parameter to filter the search for siblings.
The following example returns all sibling elements of <h2> that are <p> elements:
$(document).ready(function(){
$("h2").siblings("p");
});
The jQuery next() method returns the next sibling element of the selected element.
The following example returns the next sibling of <h2>:
$(document).ready(function(){
$("h2").next();
});
The jQuery nextAll() method returns all next sibling elements of the selected element.
The following example returns all next sibling elements of <h2>:
$(document).ready(function(){
$("h2").nextAll();
});
The jQuery nextUntil() method returns all next sibling elements between two given arguments.
The following example returns all sibling elements between a <h2> and a <h6> element:
$(document).ready(function(){
$("h2").nextUntil("h6");
});
The jQuery prev() method returns the previous sibling element of the selected element.
The following example returns the previous sibling of <h2>:
$(document).ready(function(){
$("h2").prev();
});
The jQuery prevAll() method returns all previous sibling elements of the selected element.
The following example returns all previous sibling elements of <h2>:
$(document).ready(function(){
$("h2").prevAll();
});
The jQuery prevUntil() method returns all previous sibling elements between two given arguments.
The following example returns all sibling elements between a <h2> and a <h6> element:
$(document).ready(function(){
$("h2").prevUntil("h6");
});
How you feel about this blog:
Share this blog on:
If you find any error in the turtorials, or want to share your suggestion/feedback, feel free to send us email at: info@lynxsia.com
Contact UsWe are concern with various development process like website design & development, E-commerce development, Software development, Application development, SMS & Bulk SMS Provider, PWA Development, and many more..
Copyright ©
, Lynxsia IT Solutions, All rights reserved