less/less.js — pull request #1482 by owiber (2013-08-10 03:00:59+00:00)
Title: Always properly insert style block into head

When client-side compiling, if the referenced LESS file is the last element in the `

`, this code:

```
var nextEl = sheet && sheet.nextSibling || null;
(nextEl || document.getElementsByTagName('head')[0]).parentNode.insertBefore(css, nextEl);
```

...ends up inserting at the end of `` instead since it gets the parent of `

` instead of a sibling element.

I'm fixing this by appending to `

` if `nextEl` is `null`.

It might not be necessary anymore, but just in case `oldCss` winds up outside of `

` I also adjusted the code that removes it from the DOM to not assume it'll be there so it always properly removes it.