Insertion Around Flashcards
Wrap
element.wrap(‘
’);
Quick & dirty way. Destroys all event hooks, etc. Use with caution:
element.outerHTML = ‘
’ + element.outerHTML + ‘
‘;
Safe
var wrapper = document.createElement(‘div’); element.before(wrapper); wrapper.append(element);
WrapAll
elements.wrapAll(‘
’);
ES6
var wrapper = document.createElement(‘div’); elements[0].before(wrapper); elements.forEach(x => wrapper.append(x));
ES5
var wrapper = document.createElement(‘div’); elements[0].before(wrapper); elements.forEach(function(element) { wrapper.append(element); });
WrapInner
element.wrapInner(‘
’);
Quick & dirty way. Destroys all event hooks, etc. Use with caution:
element.innerHTML = ‘
’ + element.innerHTML + ‘
‘;
Safe
var wrapper = document.createElement(‘div’); while (element.firstChild) wrapper.append(element.firstChild); element.append(wrapper);
unwrap
element.unwrap();
Quick & dirty way. Destroys all event hooks, etc. Use with caution
var wrapper = element.parentElement; while (wrapper.firstChild) wrapper.before(wrapper.firstChild); wrapper.remove();