javascript - jQuery onclick can't reach a function -


i have code:

cs = new object();   cs.show = function() {      $.getjson('script.php', function(rd) {         var result = '<button id="sellbutton">place trade offer</button>';          $('#somedom').html(result);            $('#sellbutton').click(function() {             cs.dosomething();                                                              })     }) }  cs.dosomething = function() {     // doing } 

when click button, i'm getting:

uncaught typeerror: cs.dosomething not function(…)

where problem?

in code there again set "cs" variable. after cs.dosomething called.

good solving prevent situation while development including functions inside , using var set variable name reference in actual scope.

var globalvars = {};         globalvars.cs = new object();       globalvars.cs.show = function() {          $.getjson('script.php', function(rd) {             var result = '<button id="sellbutton">place trade offer</button>';              $('#somedom').html(result);                $('#sellbutton').click(function() {                 cs.dosomething();                                                                  })         })     }      globalvars.cs.dosomething = function() {         // doing     } 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -