semi unrelated, but does this actually work?
```javascript
if (after) {
   ...
} else {
  ...
  parent = after.parent();
```
looks to me like after could never exist when you are here?

I think it might be left over from when this was using the native js insert fuction.

also there is a comment there that might need to be updated from append to prepend

```javascript
 * @param {DOMElement} parent the parent element which will append the element as
 *   a child (if the after element is not present)
```