35

Possible Duplicate:
Testing if jQueryUI has loaded

How to check if the jQuery UI extension library to jQuery is loaded on the page?

Community
  • 1
  • 1
vsync
  • 118,978
  • 58
  • 307
  • 400

3 Answers3

38
if (typeof jQuery.ui !== 'undefined') ...

Should work.

See also this SO post.

Community
  • 1
  • 1
Brad Christie
  • 100,477
  • 16
  • 156
  • 200
  • 1
    @vsync: I [stronly disagree](http://jsfiddle.net/ZrXqR/) (play with checkbox for jQuery UI checkbox on left and hit "Run") – Brad Christie Nov 08 '11 at 15:38
  • 3
    (typeof jQuery.ui === 'function') cuts out any ambiguity. – dewd Jul 23 '14 at 08:19
  • I agree with @vsync. If jQuery AND UI both aren't loaded, there's a false positive here. **That answer**, even if accepted/upvoted 28 times since 6 years, **is wrong**. **The correct type to expect from `typeof(jQuery.ui)` is `object`**. A property like `tabs` is a `function`. If UI isn't loaded, `typeof(jQuery.ui.tabs)` will throw an error about undefined property. **So the best test is** `if(typeof(jQuery.ui) == "object") { if(typeof(jQuery.ui.tabs) == "function"){ console.log("jQuery-UI loaded")}}`. -- NOTICE that the need for a nested if condition is to avoid the undefined property error. – Louys Patrice Bessette Sep 18 '17 at 16:46
35

Can check:

$.ui

Or get the version:

$.ui.version
mikeycgto
  • 3,368
  • 3
  • 36
  • 47
0

Just make sure you put any code that calls it in $(document).ready(). At that point, everything should be loaded on the page.

mccow002
  • 6,754
  • 3
  • 26
  • 36
  • I use scripts at bottom, always (before closing BODY tag). also, I want to know if the UI script is available on the page or not, as it's an unknown factor – vsync Nov 08 '11 at 15:36
  • 2
    Just because jQuery is loaded doesn't mean jQuery UI did (for example, resource could not be found, trouble loading, etc.) – Brad Christie Nov 08 '11 at 15:36