nit: same here, it's probably easier to just check the previous node is not in the DOM (parentNode == null) and that there is a new different one.