0

My query is a bit trivial but I am not sure if I am doing everything correctly.

I am trying to call a function when a checkbox is clicked.

window.onload = function(){
$("#checkboxid").click(myfunction());
}

function myfunction (){
//Code here
}

The myfunction function isn't called upon clicking the checbox and I have checked in the browser debugger as well that it's not being called. Can anyone please help in pointing out why?

1 Answers1

0

Remove () from where you call myfunction

window.onload = function() {
  $("#checkboxid").click(myfunction);
}

function myfunction() {
  console.log('here')
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<input type="checkbox" id="checkboxid" label="Click Me">
depperm
  • 10,606
  • 4
  • 43
  • 67