Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery change event is not working with checkbox

<tr>
  <td class="large-width">
    <p>
      <label>
        <input type="checkbox" id="checkbox" ${todo.isCompleted ? 'checked="checked"' : ''} />
        <span class="text">${todo.item}</span>
      </label>
    </p>
  </td>
</tr>

<script>
   $('#checkbox').change(function(){
     console.log('something');
   });
</script>

I can see that checkbox is changing it's state, but Change event is not working. I also tried on('change') and click events - they're not working either. By the way, I'm using materializecss.

like image 335
snvk3 Avatar asked Oct 24 '25 13:10

snvk3


1 Answers

Need to call below jQuery methods to working code

$(document).ready(function(){ // jQuery methods go here... });

OR

$(function(){ // jQuery methods go here... });

<tr>
  <td class="large-width">
    <p>
      <label>
        <input type="checkbox" id="checkbox" ${todo.isCompleted ? 'checked="checked"' : ''} />
        <span class="text">${todo.item}</span>
      </label>
    </p>
  </td>
</tr>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>$(document).ready(function(){
   $('#checkbox').change(function(){
     console.log('something');
   }); });
</script>
like image 181
Umesh Avatar answered Oct 27 '25 03:10

Umesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!