javascript - how to return true/false from nested jquery callback functions -
i trying validate elements inside javascript function contains 2 jquery callback loops. based on conditions want return true
/false
inner jquery loop , should sent calling method of javascript. if result of inner loop true
loop should stop running.
if(validate(key)){ } else{ } function validate(key) { $jquery.each(function(){ $jquery.each(function(){ if(){ return true; } else{ return false} }) }) }
i think you're looking for, stop both loops when true
condition met
function validate(key) { var result = false; $jquery.each(function(){ $jquery.each(function(){ if(){ result = true; return false;//break inner loop } }); if(result) return false; //break outer loop if got true in inner }); return result; }
demo fiddle can open console , see loop stops when true condition met
Comments
Post a Comment