I'm trying to insert an element before an element wrapping over the body but getting the following
Uncaught TypeError: Cannot read property 'insertBefore' of null
document.querySelector( 'body' ).innerHTML = '<div id="boat">' + document.querySelector( 'body' ).innerHTML + '</div>';
var sailor = document.createElement( 'aside' );
sailor.setAttribute( 'id', 'sailor' );
sailor.parentNode.insertBefore( document.getElementById( 'boat' ), sailor );
Any ideas on how to realize the following structure?
<body>
<aside id="sailor"></aside>
<div id="boat">
<!--
rest of the content -->
</div>
</body>