←back to thread

Element: setHTML() method

(developer.mozilla.org)
170 points todsacerdoti | 5 comments | | HN request time: 0.518s | source
1. codedokode ◴[] No.45677417[source]
I don't like this. This could be implemented as a JS library. I believe browsers should provide the minimal API so that they are smaller and easier to create. As for safe alternative to innerHTML, it is called innerText.
replies(3): >>45677474 #>>45677546 #>>45677680 #
2. csmantle ◴[] No.45677474[source]
I think innerText and setHTML() have different purposes. The former inserts the whole string as a text leaf, while the latter tries to preserve structures that are meaningful in context.

---

Libraries can surely do the same job, but then the exact behavior would vary among a sea of those libs. Having specs defined [0] for such an interface would hopefully iron out much of these variations, as well as enabling some performance gains.

[0]: https://wicg.github.io/sanitizer-api/#dom-element-sethtml

replies(1): >>45677927 #
3. petralithic ◴[] No.45677680[source]
> I believe browsers should provide the minimal API so that they are smaller and easier to create.

That ship has long since sailed. Browsers are so complex that it takes quite some effort to support the various levels of 9s of the percentage of compatibility with standards, not to mention the browser makers themselves define many of the standards.

replies(1): >>45677947 #
4. codedokode ◴[] No.45677927[source]
And if you need something that is not in a spec, you have to use a library anyway. Also the point was that browser should be as simple as possible and not like a whole new OS.
5. ◴[] No.45677947[source]