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
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#