Okay, to get slightly more interesting: adding something new to a page.
Used to be, I used to think doing this absolutely required obscure, weird techniques, starting with document.createElement()
and then having to meticulously build up the thing you’re creating step by step using a bunch of element
and document
methods before sticking the thing in the right place with an Node.appendChild()
call on something else in the document. Hard!
Nowadays, I'm realizing that for totally basic usage, it's okay to write HTML using template literal syntax— those strings that have the backtick marks, `like these`
, at the start and end. Then, you can put that HTML into the exact right spot using Element.insertAdjacentHTML()
. It's...kind of simple.
I'm not sure there's much to add to the "library" for this, though, at this point. My demo code has a createListItem()
function but that's pretty specific to the need of the demo.