I'm trying to debug a website, and I think that jQueryUI may not have loaded properly. How can I test if jQueryUI has loaded?
7 Answers
if (jQuery.ui) {
// UI loaded
}
OR
if (typeof jQuery.ui != 'undefined') {
// UI loaded
}
Should do the trick

- 56,972
- 13
- 121
- 140

- 3,834
- 1
- 30
- 37
-
2my problem is that I load jQuery and jQuery.ui dynamically. It sometimes loads in time, sometimes not. If ui is not loaded, how can I wait for it (or force it to be loaded) before calling any method? – Gabriel Diaconescu Sep 14 '11 at 10:10
-
17not sure if this makes much of a difference, but going with Boilerplate's test for jquery, they use `window.jQuery` so for jQuery UI I use the test `window.jQuery.ui` – Tim B James Nov 22 '11 at 11:31
-
this doesn't work for me. can someone please take a look at this jsfiddle and let me know if i'm doing something wrong. http://jsfiddle.net/vEvYv/1/ I expect the else of my if statement to run because I am not loading jQuery. except, it fails on the first line. Run the page with your browser console open (im using FF) and see the line `jQuery is not defined` – Dave Haigh Jun 07 '12 at 10:33
-
2@DaveHaigh - you haven't loaded JQuery. JQuery UI depends on JQuery. – Chris Haines Jun 27 '12 at 13:11
You need to check if both, the jQuery UI Library file and CSS Theme are being loaded.
jQuery UI creates properties on the jQuery object, you could check:
jQuery.ui
jQuery.ui.version
To check if the necessary CSS file(s) are loaded, I would recommend you to use Firebug, and look for the theme files on the CSS tab.
I've seen problems before, when users load correctly the jQuery UI library but the CSS theme is missing.

- 807,428
- 183
- 922
- 838
-
To check if some particular functionality is loaded the check would look like (e.g. for tooltip) ........................ `if( typeof jQuery().tooltip != "undefined" )` – jave.web May 05 '16 at 09:29
I know this is an old question, but here is a quick little script you can use to wrap all your jQuery UI things that don't have an associated event to make sure they get executed only after jQuery UI is loaded:
function checkJqueryUI() {
if (typeof jQuery.ui != 'undefined') {
do_jqueryui();
}
else {
window.setTimeout( checkJqueryUI, 50 );
}
}
// Put all your jQuery UI stuff in this function
function do_jqueryui() {
// Example:
$( "#yourId" ).dialog();
}
checkJqueryUI();

- 23,542
- 14
- 76
- 87
Just test for the ui object, e.g.
<script src="jquery.js"></script>
<script src="jquery-ui.js"></script>
<script>
$(function(){
// did the UI load?
console.log(jQuery.ui);
});
</script>

- 1,504
- 12
- 16
You can check if jQuery UI is loaded or not by many ways such as:
if (typeof jQuery.ui == 'undefined') {
// jQuery UI IS NOT loaded, do stuff here.
}
OR
if (typeof jQuery.ui != 'function') {
// jQuery UI IS NOT loaded, do stuff here.
}
OR
if (jQuery.ui) {
// This will throw an error in STRICT MODE if jQuery UI is not loaded, so don't use if using strict mode
alert("jquery UI is loaded");
} else {
alert("Not loaded");
}

- 5,666
- 2
- 27
- 41
Well, you are using jQuery to check for the presence of jQuery. If jQuery isn't loaded then $() won't even run at all and your callback won't execute, unless you're using another library and that library happens to share the same $() syntax.
window.onload = function(){
if(window.jQuery){
if(window.jQuery.ui){
}else{
console.log("jquery ui isn't loaded");
}
}else{
console.log("jquery isn't loaded");
}
}
I created 2 helper functions to load stuff dynamically, returning a promise.
window.jsinclude = (javascriptfile) => {
return new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = javascriptfile;
script.type = "text/javascript";
script.onload = resolve;
script.onerror = reject;
script.defer = true;
document.head.append(script);
});
}
window.cssinclude = (cssfile) => {
return new Promise((resolve, reject) => {
const cssf = document.createElement("link");
cssf.rel = "stylesheet";
cssf.type = "text/css";
cssf.href = cssfile;
cssf.onload = resolve;
cssf.onerror = reject;
document.head.append(cssf);
});
}
-
As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 30 '23 at 17:55