I have a field for the user to enter a CSS selector, and I want to check if it is valid (according to the css3 specification ). I tried using the expressions from the css3 specification , as suggested in https://stackoverflow.com/a/3/412743/169 , but it didn’t work - the regular expression I built just didn't match the valid selectors. At the moment, I just:
try {
document.querySelector(selector);
} catch (e) {
}
But this does not seem like a good solution. The querySelector function is for retrieving elements, and checking the selector is just a side effect. In addition, it does not provide any information about what is wrong with the selector.
I am looking for something like document.validateSelectoror a library for parsing CSS selectors.
source
share