Last Updated: February 25, 2016
·
650
· itaqua

jQuery Version Verifier

The following is a little snipplet to check if the current JQuery version installed is at leas whatever you need...

example: isJQueryVersionAtLeast(1,2,3)

I wrote this down because i found that the usual way of doing it through REG EXPs fails on mayor versions.

function isJQueryVersionAtLeast(mayor, minor, fix){
    var minVersion = [mayor,minor, fix];

    var currVersion =  $.map($.fn.jquery.split('.'), function(item, index){
        return parseInt(item);
    });

    return currVersion[0] > minVersion[0] ||
            (currVersion[0] == minVersion[0] && 
                 (currVersion[1] > minVersion[1] ||
                      (currVersion[1] == minVersion[1] && 
                          currVersion[2] >= minVersion[2])));
}

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside