37
$\begingroup$

Possible Duplicate:
Testing if jQueryUI has loaded

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

$\endgroup$
4
  • 3
    $\begingroup$ Have you seen this question? stackoverflow.com/questions/2260250/… $\endgroup$ Commented Nov 8, 2011 at 15:32
  • $\begingroup$ wow, the search functionality for stackoverflow is so bad..I was really looking around before posting this and was amazed no one asked this before. 10x. $\endgroup$ Commented Nov 9, 2011 at 8:08
  • $\begingroup$ I would delete this question if I could...no need for copies. $\endgroup$ Commented Nov 9, 2011 at 8:09
  • $\begingroup$ alert($.ui.version) ; $\endgroup$ Commented Jun 16, 2016 at 11:26

3 Answers 3

39
$\begingroup$
if (typeof jQuery.ui !== 'undefined') ...

Should work.

See also this SO post.

$\endgroup$
Sign up to request clarification or add additional context in comments.

3 Comments

@vsync: I stronly disagree (play with checkbox for jQuery UI checkbox on left and hit "Run")
(typeof jQuery.ui === 'function') cuts out any ambiguity.
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.
36
$\begingroup$

Can check:

$.ui

Or get the version:

$.ui.version
$\endgroup$

Comments

0
$\begingroup$

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

$\endgroup$

2 Comments

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
Just because jQuery is loaded doesn't mean jQuery UI did (for example, resource could not be found, trouble loading, etc.)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.