且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

验证css选择器

更新时间:2023-02-11 11:36:16

This should validate 99% of what you can throw at jQuery with far less overhead

function validateQuery(str) {
    try {
        document.querySelector(str);
        return true;
    }
    catch(e) {
        // something here to check WHY it's invalid
    }
    return false;
}

edit: ok, this wont tell you WHAT is wrong with it, but it does (quickly) check the validity - at least you'll only need to check WHY it's invalid, not IF :p