Does anybody know how I can get the equivalent of jQuery’s .offset() and .closest() without a JavaScript library?
For .closest(), if I know how far to climb up the DOM tree, I can just use that many .parentNodes, but if I don’t know how far to go, I’m stuck.
jQuery is javascript at its core. You can use this jQuery source viewer to find out implementation of any method.
For example, here is how
closestis implemented:And here is the implementation of the
offset: