I wouldn't say so, since it's a general purpose framework. In most languages you use a framework to build GUI applications. Working with the DOM in pure JS is pretty verbose.
I don't mean to make this into a code golf thread, but saying it "can't" be done in plain JS was too enticing not to try it. Does this meet the requirements?
While I think there's always the standard caveat around code golf in JS (you're building on a vast set of APIs and an often resource hungry platform), reaching for a framework really doesn't feel in the spirit of this kind of puzzle.
> I don't mean to make this into a code golf thread
Too late. Golfing notes:
• Your `win` variable is unnecessary: window is approximately the global object (look into globalThis for the subtleties of how window isn’t quite the global object), so you can drop your “win.” every time, e.g. win.c.removeChild(b) can be just c.removeChild(b).
• parent.appendChild(child) → parent.append(child) and parent.removeChild(child) → child.remove(), using newer, shorter DOM methods.
• Skip quotes on attribute values, and trailing slashes are 100% superfluous in HTML (they’re explicitly ignored, as an XHTML compatibility mechanism; I reckon they’re actually a slightly bad thing rather than harmless).
And this is why code golf is fun regardless of language!
The first two are new to me, so thank you, I'll read up. The third succinctly explains a quirk I've never bothered to check the legitimacy of, so thank you again.
With your changes, that brings us way below the character limit, sitting at 208 characters with the <body> and <script> tags the challenge dictates.
I had to rejig things to use parent.append(child) as it doesn't return the element, but using the child.remove() method directly means there's no parameter and therefore one less character there, so it all balances out. I also had to rename the event variable as it caused a scoping conflict for the variable `a`.
With all that space left over you could certainly add in the clear all and strike-through behaviour properly. Maybe even some real state!
Combining yours & the strike thru example, managed to get both strike thru & clear added in 277 chars. If i could save another char could close the p which would be nice :p
Ah yes, I’d completely forgotten that appendChild returns the child element and append doesn’t, because it’s so long since I actually had cause to use the appendChild return value!
I wonder if document.write() would work for you. The old-fashioned APIs from before the DOM era (e.g innerHTML, innerText) generally seem to be a lot shorter although they're still a bit verbose.