DOM Navigation without jQuery
Text nodes can be painful when navigating the DOM. Let's disregard them without jQuery!
function getNextSibling(el) {
el = el.nextSibling;
while (el) {
if (el.nodeType !== 3) {
return el;
}
el = el.nextSibling;
}
}
This will let you get the next sibling of the element you grabbed without worrying about text nodes.
Written by Alex Sears
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Javascript
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#