How to check whether JQuery has been loaded or not

Posted on

The title of this article describing on a subject about how to do a simple checking about JQuery load process. The simple checking process is involved in order to make sure before the actual JQuery snippet code is inserted and furthermore it is going to be executed.

Sometime, there are certain model of creating web by combining and joining several files into one main file. That main file is actually comprised from several components made by using template model. The template can be arranged into certain parts where the those parts are header, sidebar, content, footer or any other parts which is deliberately separated in several files represented each of the parts. It is intended to be written into several parts because there is going to be quite troublesome whenever the content of each files are contained in one main file. The maintenance of one file with long content will be very difficult compared to several files with the specific content representing the part of the page.

So, whenever the executed file which is actually the main file consists of several files loaded and it cannot be ensured which file represented which part loaded the JQuery library, just add the following script to check it  :

$(document).ready(function () {
   if (jQuery) {
       // jQuery is loaded
       alert("JQuery is working. It is officially loaded !");
   } else {
       // jQuery is not loaded
       alert("I dont' know. JQuery is not working. Has it been properly loaded ?");

The above script can be inserted in the tag <script></script> which is indicating that the part itself is an actual source code and it must be treated as a script precisely the client-side script and in this context it is Javscript. Moreover, in the example used in this article, the position of the source code or the script is located under the <body></body> tag declaration. The position can be assumed will not affected the script above. But one thing for sure, it must be placed after the definition of the import JQuery library file. Placing it before the JQuery file definition load process will not make the script or the snippet code above working normally.

Beside the above method for checking the JQuery functionality, there might be another way to check it. Seems the most popular technique found based upon the searching proces done using google search engine is using the above mechanism. Different snippet code with the actual similar method.

3 thoughts on “How to check whether JQuery has been loaded or not

Leave a Reply