Monday, July 12, 2010

How to check loaded jQuery UI version?

In this post I will show how to check currently loaded jQuery UI version on the page. Unlike checking loaded jQuery version ( $().jquery ), checking jQuery UI version is a bit different.

Checking currently loaded jQuery UI version on the page:

// Returns jQuery UI version (ex: 1.8.2) or undefined
$.ui.version

// Alternatively
jQuery.ui.version

You would most probably use it in the if statement:

if($.ui && $.ui.version){
    // jQuery UI is loaded
}
You can also check if jQuery UI is loaded or not:
// Checking if jQuery UI is loaded or not
if($.ui){
    // jQuery UI is loaded
}else {
    // jQuery UI is not loaded
}

3 comments:

  1. should not you better check ($.ui && $.ui.version)?
    i mean, if $.ui is undefined, then $.ui.version will thrown an exception. isn't it?

    ReplyDelete
  2. @Michael Moossen, You are absolutely right. Thanks for the heads up. Updated the post.

    ReplyDelete
  3. this is actually not true. if the first statement evaluates to false, the second one will not even be checked, since we use an && operator.

    ReplyDelete