Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule proposal: prefer getHTML/setHTML to .innerHTML #2347

Open
fregante opened this issue May 9, 2024 · 2 comments
Open

Rule proposal: prefer getHTML/setHTML to .innerHTML #2347

fregante opened this issue May 9, 2024 · 2 comments

Comments

@fregante
Copy link
Collaborator

fregante commented May 9, 2024

Description

See context for the Sanitizer API in https://fullystacked.net/innerhtml-alternatives/

Fail

main.innerHTML = '<h2>Mambo Nº2</h2>'
console.log(main.innerHTML);

Pass

main.setHTML('<h2>Mambo Nº2</h2>')
console.log(main.getHTML());

Related

@DEVTomatoCake
Copy link
Contributor

DEVTomatoCake commented May 11, 2024

According to MDN all major browsers removed support for <Element>.setHTML() (though not <Element>.getHTML()) again, according to Can I use it's available in about 5% of browsers. It's still in the spec, however that doesn't help if all users should be able to use your website.

Why would you prefer something which breaks the site for most users, especially on recent browser releases, with no apparent benefits by itself (if you don't use sanitizers), over something which has been working since many years?

@fregante
Copy link
Collaborator Author

The linked article has more info on why. The rule might take years to be added and even then it could be left disabled by default until Chrome implements it again. Browsers are quick to update nowadays

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants