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

java - How to Configure JAXRS and Spring With Annotations -

visual studio - TFS will not accept changes I've made to a Java project -

php - Create image in codeigniter on the fly -