views:

565

answers:

4

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?

A: 

To test whether the jQuery UI library specifically is loading, add <div id="test" title="test">test</div> to your <body> and use this script in your <head>:

<script>
  $(document).ready(function() {
    $.ui.dialog.defaults.bgiframe = true;
    $("#test").dialog();
  });
</script>

If you're a Firefox/Firebug user (http://getfirebug.com/), you can open Firebug, click the "Script" tab, and click the drop-down menu next to "all" in order to see the loaded scripts. You should see the jquery-ui script in that list.

It could be possible that the base jQuery library, which is required by the UI library, isn't loading. To test for that possiblity,put this into your <head> tag:

<script>
  $(document).ready(function() {
    alert('jquery loaded!');
  });
</script>

If you get no alert, try adding this:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"&gt;&lt;/script&gt;

That will load jquery from Google's servers, which would give a hint that the browser can't find the script where you were pointing to.

Ryan Prior
+1  A: 

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>
bdl
+3  A: 

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.

CMS
+8  A: 
if (jQuery.ui) {
  // UI loaded
}

OR

if (typeof jQuery.ui != 'undefined') {
  // UI loaded
}

Should do the trick

chrismacp
4 spaces before a line formats as code. `ctr-k` for a selection.
Peter Ajtai