I'm not if this has been pointed out before (I've seen someone having a similar issue to my self, but I've found a reproducible way of identifying the bug), so I thought I'd post it.
Please let me know if I'm simply doing something wrong, but when I try to change different aspects of the same node, the node is not updated. This is triggered by trying to modify the innertext, and the outertext, or (I don't give an example of this, but it does happen in my application) a child selected (e.g. modify ('head', 0)->innertext then ('head', 0)->find('script')->innertext).
I have uploaded some sample code as a gist, which will hopefully demonstrate the issue:
Sorry again if this is simply my misuse.