Nested HTML is moved incorrectly

If the tabs component the script is applied to contains nested HTML (for instance a &lt;ul&gt; containing &lt;li&gt; nodes) the structure will not be preserved when switching between components. The DOM items will be added after each other which results in invalid HTML (as the list items will be outside of the list).

The issue can be observed in the following fiddle: http://jsfiddle.net/yVz7v/4/
Solved with the fix applied in my fork: http://jsfiddle.net/yVz7v/3/