JS DOM: Button 🔲

By Xah Lee. Date: . Last updated: .

Button Example

Code

<button id="button_mw2t" type="button">Click Me</button>

<span id="output_z9nz"></span>
"use strict";
{
    const button_mw2t = document.getElementById("button_mw2t");
    if (button_mw2t === null)
        throw (new Error(`id button_mw2t is missing.`));

    const output_z9nz = document.getElementById("output_z9nz");
    if (output_z9nz === null)
        throw (new Error(`id output_z9nz is missing.`));

    const f_update = () => {
        output_z9nz.textContent = output_z9nz.textContent + "clicked ";
    };
    button_mw2t.addEventListener("click", f_update);
}