Insertion Around Flashcards

1
Q

Wrap

element.wrap(‘

’);

A

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);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

WrapAll

elements.wrapAll(‘

’);

A

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); });

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

WrapInner

element.wrapInner(‘

’);

A

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);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

unwrap

element.unwrap();

A

Quick & dirty way. Destroys all event hooks, etc. Use with caution

var wrapper = element.parentElement; while (wrapper.firstChild) wrapper.before(wrapper.firstChild); wrapper.remove();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly