Insertion Inside Flashcards
Append element to single target
target.append(element);
target.appendChild(element);
Append element to a set of targets
targets.append(element);
ES6
for (var target of targets) target.appendChild(element.cloneNode(true)); element.remove();
ES5
targets.forEach(function(target) { target.appendChild(element.cloneNode(true)); }); element.remove();
$(parent).prepend(el);
parent.insertBefore(el, parent.firstChild);
Get element html
var html = element.html();
var html = element.innerHTML;
Set element html
element.html(‘
foo
’);
element.innerHTML = ‘
foo
’;
Set html to a set of elements
elements.html(‘
foo
’);
ES6
elements.forEach(x => x.innerHTML = ‘
foo
’);
ES5
elements. forEach(function(element) {
element. innerHTML = ‘
foo
’;
});
Get element text
var text = element.text();
var text = element.textContent;
Get element text from a set of elements
vvar text = elements.text();
ES6
var text = elements.map(x => x.textContent).join(‘’);
ES5
var text = elements.map(function(element) {
return element.textContent;
}).join(‘’);
Set element text
element.text(‘foo’);
element.textContent = ‘foo’;
Set text to set of elements
elements.text(‘foo’);
ES6
elements.forEach(x => x.textContent = ‘foo’);
ES5
elements.forEach(function(element) { element.textContent = ‘foo’;
});