|
|
|
|
|
by pseudosavant
1495 days ago
|
|
Update: fixed formatting A lot of times the jQuery syntax is easier to understand (IMO). Remove element exmample: jQuery API: $('.element').remove()
DOM API: document.querySelector('.element').parentNode.removeChild(document.querySelector('.element'))
or if you want to introduce another variable just to remove the element: const child = document.querySelector('.element');
child.parentNode.removeChild(child);
Create element example:jQuery API: const fooElement = $('<div class="foo" style="display: none">')
DOM API: const fooElement = document.createElement('div');
fooElement.classList.add('foo');
fooElement.setAttribute('style', 'display: none');
I know which ones I'd rather write and read. |
|
https://developer.mozilla.org/en-US/docs/Web/API/Element/rem...
Also for element creation:
Object.assign(document.createElement("div"), { class: "foo", style: "display:none" });
I mean, you normally abstract these things with a helper fn or two, without importing the whole jQuery anyway.