Really simple: how do I most accurately test if a browser has support for a certain CSS selector?
I currently have some CSS code that makes the page a little more in
A shorter way to do it would be to simply try the query selector, if it produces an error, return false, else true, like this:
function testSelector(selector) {
document.querySelector('*'); //checks if querySelector is implemented and raises an error if not
try {document.querySelector(selector)} catch (e) {return false}
return true;
}
I checked it on IE9 Windows and Chrome Mac (V43.0.2357.130), Win(V39.0.2171.95m), FireFox Win (V38.0.5), and it works fine with testSelector("form:invalid"), which is not implemented by IE9, but by everybody else.