Jquery Sibling Traversing

Jquery siblings()

The siblings() method returns all sibling element of selected element.

$(document).ready(function(){
 $('span').siblings().css({
  fontSize: '20px',
  color: 'black'
 });
});


Jquery next()

The next() method returns the next sibling element of selected element.

$(document).ready(function(){
 $('span').next().css({
  fontSize: '20px',
  color: 'black'
 });
});


Jquery nextAll()

The nextAll() method returns all next sibling element of selected element.

$(document).ready(function(){
 $('span').nextAll('p').css({
  fontSize: '20px',
  color: 'black'
 });
});


Jquery nextUntil()

The nextUntil() method returns all next sibling element between two given argument.

$(document).ready(function(){
 $('span').nextUntil('p').css({
  fontSize: '20px',
  color: 'black'
 });
});


Other similar sibling method are:

- prev()
- prevAll()
- prevUntil()

Share this

Related Posts