javascript - how to get variable value within function? -
how can return variable value within function?
var mystring = "px"; var mymethod = function(){ if(mystring == 'percent') { return '%'; } else { return mystring; // should return 'px' } $('div').css('width','200'+mymethod()); //not working
as i'm having problem this:
var scalc = this.classname.split('-')[4]; var fncalc = function(){ if(scalc == 'plus'){ return '+'; } else if(scalc == 'minus'){ return '-'; } else if(scalc == 'multiply'){ return '*'; } else if(scalc == 'divide'){ retutn '/'; } else{ return '+'; } /*bugging me much*/ };
i'm not seeing error in console?
you're missing curly brace end function.
var mystring = "px"; var mymethod = function() { if (mystring == 'percent') { return '%'; } else { return mystring; // should return 'px' } }; $('div').css('width','200'+mymethod()); //not working
updated jsfiddle
Comments
Post a Comment