vendredi 17 février 2017

select checkbox with enter key

I have a few checkboxes that I need to be selected with the enter key instead of the space bar when it has focus. I have the code below that works for one check box, but I need multiple checkboxes. I know the id tag needs to be unique, but I'm not sure how to do it.

    $(document).ready(function () {
    $('#mycheckbox').on('keypress', function (event) {
        if (event.which === 13) {
            this.checked = !this.checked;
        }
    });
});

<input type="checkbox" name="Colors" value="Bike" id="mycheckbox">My text<br>

I'm trying to get this to work on all the checkboxes not just the one with the mycheckbox id.




Aucun commentaire:

Enregistrer un commentaire