I have html code <input onclick="function_name(1)"> and I want to use it in Jquery something like function function_name(i) { alert(i); }. It doesn’t work, any tips? Thank you.
I have html code <input onclick=function_name(1)> and I want to use it in Jquery
Share
The way your code is written, it should work.
If the
function_nameisn’t firing, then it could be because you haven’t defined it in the global scope.For example, if you’re using jQuery, this won’t work because the function isn’t global:
But this will, because you’ve made the function global:
Or this will, because you’ve explicitly made it global from inside
.ready().Aside from the global issue, I’m not sure why your code would fail from the
onclick=attribute.