Javascript examples for DOM:Element parentNode
create element and insert before an element with element.parentNode.insertBefore
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){//w w w . j av a 2s . com function wrapElem(el, wrapWith) { var newElem = document.createElement(wrapWith); el.parentNode.insertBefore(newElem, el); newElem.appendChild(el); } wrapElem(document.getElementsByTagName('input')[0], 'div'); } </script> </head> <body> <input type="text"> </body> </html>