jquery Function to return object -
i have function supposed return object when finds it's not doing that. doing wrong?
var getel = function(title){ var theinputs = $('input[type=text], input[type=radio], input[type=checkbox], select, textarea') theinputs.each(function(){ if (this.title==title){ getel = console.log('found it!') } }) } console.log(getel('office status'))
i know works since found output on console, console reports undefined output of line:
console.log(getel('office status'))
var getel = function(title){ var result; var theinputs = $('input[type=text], input[type=radio], input[type=checkbox], select, textarea') theinputs.each(function(){ if (this.title==title){ result = console.log('found it!') return false; // break loop } }); return result; }
overwriting value of functions variable not work. want instead return result.
edit:
that being said, should able replace whole thing this:
var $result = $(":input[title='" + title + "']"); if(result.length > 0) return $result[0];
though it'll need modification if need 3 types of inputs instead of input. (using existing theinputs
variable):
var $result = theinputs.filter("[title='" + title + "']");
Comments
Post a Comment