Well, as Russ says, since Sizzle interprets the selector, he cannot test it without evaluating it.
However, you can catch the exception thrown by Sizzle to determine if the selector is valid or not:
function isSelectorValid(selector)
{
try {
$(selector);
} catch (x) {
return false;
}
return true;
}
You can check this solution here .
The EDIT: . For the story, my original (and reconfigured) answer was:
, Sizzle, . , jQuery Sizzle $.find ():
function isSelectorValid(selector)
{
var oldErrorMethod = $.find.error;
try {
$.find.error = function(msg) {
valid = false;
oldErrorMethod(msg);
};
$(selector);
return true;
} catch (x) {
return false;
} finally {
$.find.error = oldErrorMethod;
}
}
, : .