• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
JavaScriptSource

JavaScriptSource

Search 5,000+ Free JavaScript Snippets

  • Home
  • Browse Snippets
    • Addon
    • Ajax
    • Buttons
    • Cookies
    • CSS
    • Featured
    • Forms
    • Games
    • Generators
    • Image Effects
    • Math Related
    • Miscellaneous
    • Multimedia
    • Navigation
    • Page Details
    • Passwords
    • Text Effects
    • Time & Date
    • User Details
Home / Miscellaneous / Get all siblings of an element

Get all siblings of an element

Get all siblings of an element

A simplified approach using some ES6 methods.

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

Source

https://vanillajstoolkit.com/helpers/getsiblings/

Miscellaneous

Related Snippets:

  • Return all the elements of an array except the last one
  • Show or hide an element
  • Perform a shallow merge of two or more objects
  • Insert an HTML string after the end of the specified element

Primary Sidebar

Popular Posts

Story Generator

IP Grabber – get a users IP address with JavaScript

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2025 JavaScriptSource.com

  • About
  • Privacy Policy
  • FAQ
  • Jobs For Developers