How to check if jquery is loaded in your theme

How to check if jquery is loadedHow to check if jquery is loaded in your theme or site.Well Answer is simple view the source code of your page.

But as a developer you want to  check if jquery is loaded if it is not then it must load the jquery there is no dynamic script except  javascript.

Also I’m introducing the jquery testing tool to test if jquery loaded. You can test online if the site is using jQuery or not so here is the tool.

jQuery Testing Tool

Now lets come to the code simple code for jquery detection is :

But this code can only  check if jQuery is loaded or not.But we want that if jQuery is not loaded then load it.
Now lets do some tweak with code:

Well this code will not work in  every case.
If the above code works well then its ok otherwise proceed further.
Now we have to introduce some kind of popup or alert.
Until the user press ok jquery will loaded in the head of your page.
I’m using the following code for my plugin JinMenu
So the code below may works in every case.

  • http://www.facebook.com/johnmotyl John Motyl

    Couldn’t it be easier to just have a link to jQuery CDN and have a small if statement to test. Consider the following:

    if (!window.jQuery) {
    var script = document.createElement(‘script’);
    script.src = “js/jquery.js”;

  • buffernow

    yes it will also work