jquery call function on click -
i facing problem calling function on click. following code:
javascript:
$(document).ready(function(){ function showmessage(msg) { alert(msg); }; })  html:
<input type="button" value="ahaha" onclick="$(this).showmessage('msg');" />  for reasons cant use click() function. please me.
a few things:
-  
showmessage()isn't property of jquery object. it's regular function. - if you're using jquery, don't use 
onclick. bind events javascript. 
there few ways of fixing code. here's one:
javascript:
$.fn.showmessage = function(message) { alert(message); }; $(document).ready(function() { $('#button').on('click', function() { $(this).showmessage('i message'); }); });  html:
<input type="button" value="ahaha" id="button" />  
Comments
Post a Comment