mardi 6 décembre 2016

Why isn't my Javascript working?

I am new to coding and I need to use Javascript in my code. I have a checkbox within an HTML table (below).

<td><input type="checkbox" id="check1"/> 
<label th:text="${item.contents}">&nbsp;</label>
</td>

I am trying to use Javascript to alert me when I have checked the box with the code below.

<script>

$('#check1').click(function() {
    if($(this).not(':checked'))
        alert('unchecked');
    else
        alert('checked');
});

</script>

Why isn't it working? I don't get an error, but nothing happens either. Thank you.

Aucun commentaire:

Enregistrer un commentaire