Home

Published

- 1 min read

create parent div javascript

img of create parent div javascript

The solution for this is noted below

create parent div javascript

Solution

   // `element` is the element you want to wrap
var parent = element.parentNode
var wrapper = document.createElement('div')

// set the wrapper as child (instead of the element)
parent.replaceChild(wrapper, element)
// set element as child of wrapper
wrapper.appendChild(element)

Try other methods by searching on the site. That is if this doesn’t work