jquery - cannot call javascript function inside click handler -


i have div loaded via ajax:

<div id="container">     <a href="#" class="easyui-linkbutton submit_data">click here submit</a> </div> 

in same file in have div, have script this:

<script>     $(function(){         $('#container').on('click', 'a.submit_data', function(e){             e.preventdefault();             alert(test());         });          function test()         {             return 'this test';         }     }); </script> 

the problem have when call function test() in callback of click event did above, error uncaught typeerror: undefined not function when click on button (so don't alert). if call test() function outside of click handler, works expected.

dpes know why happening please?

thank you

does help? i'm not sure you're looking for. cleaned script , click event.

codepen sketch

jquery

$('.submit-data').on('click', function(event){   event.preventdefault();   alert(myfunction()); });  var myfunction = function(){   return 'this test'; } 

html changed submit_data class submit-data better selector convention.

<div id="container">   <a href="#" class="easyui-linkbutton submit-data">click here submit</a> </div> 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -