How can I pass a variable to the onclick function? When using
var number = 123;
document.getElementById('myButton').onclick = myFunction(number);
It will run that function before even clicking the button because the function will be called and the return value will be put into the onclick, which doesnt help me
Without the "()" it will only call the function once I click the button, but how do I pass a variable then ?
var number = 123;
document.getElementById('myButton').onclick = myFunction;
function myFunction(i) {
i += 10;
alert(i);
}