How to check if element is last child without JQuery
You can use the .nextSibling property on the element and see if it comes back as empty (undefined, etc).
The error you get should be some kind of can't set property on undefined
.
You have just to check whether the next element exists:
if (typeof element.nextSibling === "undefined")
return;