onclick is great, actually — DeepSeek Tips & Insights
    Neura MarketNeura Market/DeepSeek
    ChatGPTChatGPTClaudeClaudeGeminiGeminiCursorCursorGrokGrokPerplexityPerplexityDeepSeekDeepSeek
    CoPilotCoPilotStable DiffusionStable DiffusionMidjourneyMidjourney
    View All Directories
    OverviewRulesPromptsMCPsAgentsGamesBlogVideosGuidesCoursesCommunityTrending
    DeepSeekBlogonclick 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:

    <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:

    <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
    Five Gemma-4 models, one accelerator: what porting E2B 31B to AWS Inferentia2 taught megemma

    Five Gemma-4 models, one accelerator: what porting E2B 31B to AWS Inferentia2 taught me

    I ported the whole Gemma-4 family — E2B, E4B, 12B, 31B, and the 26B-A4B MoE — to run on...

    X
    xbill
    Hey DEV, I'm Tobore. Let's actually connect.community

    Hey DEV, I'm Tobore. Let's actually connect.

    Hey DEV, I'm Tobore. Let's actually connect. I've been on here for a while now, mostly writing and...

    L
    Laurina Ayarah
    I burned through thousands of AI tokens. Then a friend did it for freeai

    I burned through thousands of AI tokens. Then a friend did it for free

    (yep, kinda clickbait, just for the funsies 😊) At the beginning of the year, I relaunched my...

    P
    Paulo Henrique
    Claude might be saturating your machineai

    Claude might be saturating your machine

    My laptop was sitting idle with the fan at full tilt. Nothing was running that I knew of. The culprit...

    S
    Sidhant Panda
    Automated GitHub Code Reviews Using Google Geminigithubactions

    Automated GitHub Code Reviews Using Google Gemini

    I Built a Thing! TL;DR — Google Gemini-based Pull Request reviews and Issue Triaging for...

    D
    Darren "Dazbo" Lester
    What is an "agentic harness," actually?ai

    What is an "agentic harness," actually?

    I've been hearing the word "harness" thrown around a lot lately. I assumed it just meant "the IDE" or...

    T
    Tilde A. Thurium

    Stay up to date

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

    Neura Market LogoNeura Market

    Discover the best AI prompts, plugins, and resources for DeepSeek 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.

    Neura Market

    Custom AI Systems & Services

    Our team of experienced AI builders will help build custom AI systems, workflows, and solutions for your business.

    Request custom work

    Ready-made automations for this

    Workflows from the Neura Market marketplace related to this DeepSeek resource

    • Automate Blog Content Creation with Notion MCP, DeepSeek AI, and WordPressn8n · $9.99 · Related topic
    • Generate AI Videos from Scripts with DeepSeek, Synthesia, and Together.ain8n · $24.99 · Related topic
    • Compare Multi-Period Financial Data from Google Sheets with DeepSeek AI Analysisn8n · $14.99 · Related topic
    • PostgreSQL Conversational Agent with Claude & DeepSeek (Multi-KPI, Secure)n8n · $14.99 · Related topic
    Browse all workflows