I have a function like this:
function parseValue(value, defaultValue) {
if ($.isFunction(value))
return value();
if (!value)
return defaultValue;
if ($(value).size() > 0)
return $(value).val();
return value;
};
value can be a function, a “value”, or a jquery selector. My problem is how do I determine that the selector is valid (finds a control).
for example, when value equals 56.87 $(value).size() > 0 evaluates to true. I want it to be false. Even if something like #invalidcontrolid was passed in, if it doesn’t actually exist on the page, I want to get false back so I can return the value. Any ideas?
.size()is just a wrapper method for.lengthproperty. So this should (and does) work:http://www.jsfiddle.net/EawgE/
You should check within your
parseValuemethod ifvalueactually is a number. If so, just returnfalseor whatever but don’t pass it into the jQuery constructor.or
Example: