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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -