dimanche 13 août 2017

Can't detect checkbox selection with JQuery

I'm trying to use JQuery to detect when a checkbox is selected or not. The JS I'm using is like so:

$(":checkbox").click(function() {
    if (this.checked){
      console.log("checked!");
    } else {
      console.log("not checked!");
    }
});

The checkbox in my HTML:

<input class="tgl tgl-skewed" id="cb3" type="checkbox"/>
<label class="tgl-btn" data-tg-off="$" data-tg-on="฿" for="cb3"> </label>

In the JS console I am getting the error:

ReferenceError: Can't find variable: $

What am I doing wrong here?




Aucun commentaire:

Enregistrer un commentaire