Javascript examples for DOM:Element getElementsByTagName
Get element siblings in JavaScript without using libraries
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){//from w w w.ja v a2 s . com var div = document.getElementsByTagName('div')[0]; var siblings = [].slice.call(div.parentNode.children) .filter(function(v) { return v !== div }); console.log(siblings); } </script> </head> <body> <div>a</div> <div>v</div> <div>c</div> <div>e</div> <div>w</div> <div>q</div> </body> </html>