DenisKarakchiev
7/4/2017 - 9:47 AM

func wrap | wraps the node with another node #js

func wrap | wraps the node with another node #js

function wrap(el, wrapper) {
    el.parentNode.insertBefore(wrapper, el);
    wrapper.appendChild(el);
}

// example: wrapping an anchor with class "wrap_me" into a new div element
wrap(document.querySelector('a.wrap_me'), document.createElement('div'));