onclick is great, actually β€” CoPilot Blog
    Neura MarketNeura Market/CoPilot
    ChatGPTChatGPTClaudeClaudeGeminiGeminiCursorCursorGrokGrokPerplexityPerplexityCoPilotCoPilot
    DeepSeekDeepSeekStable DiffusionStable DiffusionMidjourneyMidjourney
    View All Directories
    OverviewRulesPromptsMCPsAgentsBlogVideosGuidesCoursesCommunityPluginsTrendingGenerate
    CoPilotBlogonclick is great, actually
    Back to Blog
    onclick is great, actually
    javascript

    onclick is great, actually

    π’ŽWii πŸ³οΈβ€βš§οΈ May 13, 2026
    0 views

    A few thoughts on `onclick` and how my opinion on it has changed.

    --- title: onclick is great, actually published: true description: A few thoughts on `onclick` and how my opinion on it has changed. tags: javascript, html # cover_image: https://direct_url_to_image.jpg # Use a ratio of 100:42 for best results. # published_at: 2026-05-13 18:53 +0000 --- For several years, I've been mostly against event handling code in HTML attributes. And for the longest part, it really was a terrible idea. With modules alone, it becomes really hard for `onclick` handlers to call code. Not without polluting the global namespace, at least. But now I'm starting to warm up to them again: thanks to custom elements, code can live in modules and still be triggered via DOM attributes, by using custom elements as the interface: ```html <custom-element> <button onclick="this.closest('custom-element').doThings()"> Click Me! </button> </custom-element> ``` The actual logic, the `doThings` method, still lives in a separate model decoupled from the goings on of the DOM, and yet the button can cause it to run without needing any additional JavaScript to connect the two. The DOM is what connects the elements, which is exactly how it should be. Sadly, the web is so close yet still so far from an even better solution: ```html <button commandfor="element-id" command="--do-things"> Click Me! </button> ``` This would be an even nicer solution by eliminating the `closest()` boilerplate and replacing the method call with an event. Sadly, it only works with IDs, regardless of DOM proximity. If I could make a wish, I'd change how `commandfor` works to just take a CSS selector and treat it as an argument to the `closest()` method unless it starts with a `#`, but that's not the world we live in. In this world, `onclick` is a very good albeit slightly more verbose replacement. --- Edit to add: I should probably mention that for more complex situations, I am also quite fond of `<button x-event="custom-element:do-things">Click Me!</button>` with a click listener on the document root that intercepts click events on buttons with the `x-event` attribute and dispatches a custom event of that name instead. It's a convenient way to simplify HTML while keeping the logic mostly decoupled from the structure of the DOM.

    Tags

    javascripthtml

    Comments

    More Blog

    View all
    Minimalist EKS: The Easy Waykubernetes

    Minimalist EKS: The Easy Way

    Amazon EKS manages the Kubernetes control plane, but you remain responsible for provisioning the...

    J
    Joaquin Menchaca
    Never forget to enter the Stern Grove lottery again!ai

    Never forget to enter the Stern Grove lottery again!

    Browser automation with Playwright, Python, GitHub Actions, and Entire to auto-enter San Francisco Stern Grove concert lotteries each week!

    L
    Lizzie Siegle
    A Free Screenshot Editor That Never Uploads Your Imagetypescript

    A Free Screenshot Editor That Never Uploads Your Image

    A free screenshot and image editor that runs entirely in your browser. Keeping every edit reversible and handling big phone photos, in plain TypeScript and Canvas2D.

    M
    Martin Stark
    I built a CLI to break my highlights out of Apple Booksshowdev

    I built a CLI to break my highlights out of Apple Books

    A macOS CLI + MCP server that exports Apple Books highlights to Markdown and gives AI assistants direct access to your reading notes.

    A
    Andrey Korchak
    A Developer's Guide to Agent Hooks in Antigravity CLIai

    A Developer's Guide to Agent Hooks in Antigravity CLI

    Motivation To be quite honest, "Hooks"β€”the shell commands we trigger at specific points...

    T
    Tanaike
    Tactical vs. Strategic Agentic AI Development β€” A Playbook for Developersagents

    Tactical vs. Strategic Agentic AI Development β€” A Playbook for Developers

    The Strategic Engineer: Why Writing Code Is No Longer Your Most Valuable Skill ...

    A
    Adewumi Saheed Adewale

    Stay up to date

    Get the latest CoPilot prompts, rules, and resources delivered to your inbox weekly.

    Neura Market LogoNeura Market

    Discover the best AI prompts, plugins, and resources for CoPilot and more.

    Content Types

    • Rules
    • Prompts
    • MCPs
    • Agents
    • Guides

    Platforms

    • ChatGPT Directory
    • Claude Directory
    • Gemini Directory
    • Cursor Directory
    • Grok Directory
    • Perplexity Directory
    • DeepSeek Directory
    • CoPilot Directory
    • Stable Diffusion Directory
    • Midjourney Directory
    • All Directories

    Resources

    • Blog
    • Documentation
    • Help Center
    • Marketplace

    Legal

    • Privacy Policy
    • Terms of Service

    Β© 2026 Neura Market. All rights reserved.

    |

    Not affiliated with any AI platform vendors.