JSFiddle - React, Tailwind, and code Playground

by jruddell

HTML

<label for="mycheckbox">Click to fire</label> <input type="checkbox" id="mycheckbox" value="1" name="mycheckbox" />
<br />
<span id="output"></span>

JavaScript

$(document).ready(function() {
    // global counter to track triggers
    window.count = 0;
    
    // on change, increment counter and append html
    $('#mycheckbox').change(function() {
        window.count++;
        jQuery('#output').append('I fired: ' + window.count + ' times<br />');
    });
    
    // fire a click event
    // in jQuery 1.4.4 it DOESN'T fire the change event
    // in jQuery 1.5.2+ it DOES fire the change event
    $('#mycheckbox').triggerHandler('click');
});