all these solutions look like an overkill. Why use my solution?
previousElementSibling
supported from IE9
document.addEventListener
needs a polyfill
previousSibling
might return a text
Please note i have chosen to return the first/last element in case boundaries are broken. In a RL usage, i would prefer it to return a null.
var el = document.getElementById("child1"),_x000D_
children = el.parentNode.children,_x000D_
len = children.length,_x000D_
ind = [].indexOf.call(children, el),_x000D_
nextEl = children[ind === len ? len : ind + 1],_x000D_
prevEl = children[ind === 0 ? 0 : ind - 1];_x000D_
_x000D_
document.write(nextEl.id);_x000D_
document.write("<br/>");_x000D_
document.write(prevEl.id);
_x000D_
<div id="parent">_x000D_
<div id="child1"></div>_x000D_
<div id="child2"></div>_x000D_
</div>
_x000D_