Skip to content

Instantly share code, notes, and snippets.

@hkfoster
Created March 17, 2015 20:36
Show Gist options
  • Save hkfoster/1cb6d6c9f3da1cb92293 to your computer and use it in GitHub Desktop.
Save hkfoster/1cb6d6c9f3da1cb92293 to your computer and use it in GitHub Desktop.
Native JS node-wrapping function
function wrapNodes( nodes, type ) {
for ( var index = 0; index < nodes.length; index++ ) {
var node = nodes[ index ],
wrapper = document.createElement( type );
node.parentNode.insertBefore( wrapper, node );
wrapper.appendChild( node );
}
}
wrapNodes( document.querySelectorAll( 'pre' ), 'div' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment