Skip to main content Accessibility Feedback

getSiblings.js

Get all siblings of an element. Learn how it works.

/*!
 * Get all siblings of an element
 * (c) 2018 Chris Ferdinandi, MIT License, https://gomakethings.com
 * @param  {Node}  elem The element
 * @return {Array}      The siblings
 */
 var getSiblings = function (elem) {
 	return Array.prototype.filter.call(elem.parentNode.children, function (sibling) {
 		return sibling !== elem;
 	});
 };