1
var function1 = function (ans){
  alert("A");
}
$(document).ready({
  $("input[type='radio']").click(function1(ans));
});

If function1 has no parameter then we can just have .click(function1) and function1 will not be called.

Meanwhile, when there is a parameter, function1 is called immediately when document is loaded. How to pass a parameter to a function without having the function called ?

Rawr
  • 71
  • 1
  • 3
  • 10
  • `.click(function() { function1(ans); })`. –  Feb 08 '17 at 11:26
  • `var function1 = function (ans){ return function() { alert("A",ans); } } $(document).ready({ $("input[type='radio']").click(function1(ans)); });` – xitter Feb 08 '17 at 11:31

1 Answers1

0

You have to pass a callback function:

$(document).ready({
   $("input[type='radio']").click(function(){
         function1(ans));
   });
});

$("input[type='radio']").click(function1(ans)); triggers the click event handler automatically.

Mihai Alexandru-Ionut
  • 47,092
  • 13
  • 101
  • 128