I openly admit that I'd rather learn a new framework than touch anything to do with figuring out how the browser is intended to behave in practice. What an abomination and insult to humanity.
But what's the problem again?
``` fetch('/my-content').then(async res => { if(res.ok) { document.getElementById('my-element').innerHtml = await res.text(); } }) ```
Something like that. Doesn't get much easier. Gone are the days of browser inconsistencies, at least of you stick to "Baseline Widely available" APIs which is now prominently displayed on MDN.
You do have to call `getElementById` on a document. There can be many documents in a window.
Although a very consistent convention, there are no guardrails put in place to prevent something from setting the same id on two or more elements.
getElementById will return the first element that it finds with the id, but you can't know for sure if it is the only one without additional checks
<textarea id="userNotes"></textarea>
<button type="button" id="copyButton">Copy</button>
<script>
copyButton.addEventListener('click', () => {
navigator.clipboard.writeText(userNotes.value)
copyButton.innerText = 'Copied'
setTimeout(() => copyButton.innerText = 'Copy', 1000)
})
</script>function getId(v) {return document.getElementById(v)}
Dev tools allows $ $$, dunno, make a macro?
We must not defy the system!
const g = (x) => document.getElementById(x);I get that huge apps probably need a lot more than that, but so many people these days reach for heavy frameworks for everything, because it’s all they know.