- From: vrugtehagel <notifications@github.com>
- Date: Sun, 28 Feb 2021 11:00:19 -0800
- To: whatwg/dom <dom@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Sunday, 28 February 2021 19:00:32 UTC
A common thing to do when manipulating DOM elements is "emptying" an element, i.e. removing all its child nodes. There are currently a few solutions to this; let me list the most obvious ones.
```
element.innerHTML = '';
```
This solution is semi-readable, but invokes the DOM parser (unless specifically optimized for by the browser).
```
element.textContent = '';
```
Similar to the previous one, but less readable (as the intended operation doesn't really have anything to do with the text content specifically). This is supposedly more performant than `innerHTML`.
```
while(element.firstChild){
element.removeChild(element.lastChild);
}
```
there are various variations on this one, none of them marginally better than another. This solution works, but requires three lines of code for a simple operation that, in my opinion, should be standardized.
So, I propose adding a method like `.empty()` to the Node interface. What are your thoughts on this?
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/955
Received on Sunday, 28 February 2021 19:00:32 UTC