Check if a jquery has been loaded or not Last Updated : 16 Jan, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report Given a document, The task is to determine whether JQuery has been loaded or not, If not then load it dynamically using JavaScript. Below are the examples to check: Approach: First, check if it is loaded.If not loaded then load it dynamically, create a script element and add properties like(type, src) to it and then finally append it at the end, inside of the head element. Example 1: In this example, the JQuery is already loaded so the message 'Script already loaded!' prints on the screen. html <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"> </script> <h1 style="color:green;"> GeeksforGeeks </h1> <p id="GFG_UP"> </p> <button onClick="GFG_Fun()"> click here </button> <p id="GFG_DOWN"> </p> <script> var up = document.getElementById('GFG_UP'); var down = document.getElementById('GFG_DOWN'); up.innerHTML = "Click on button to check whether JQuery is loaded"; function GFG_Fun() { if (!window.jQuery) { var el = document.createElement('script'); el.type = "text/javascript"; el.src = "https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"; document.getElementsByTagName( 'head')[0].appendChild(el); down.innerHTML = "Script loaded successfully!"; } else { down.innerHTML = "Script already loaded!"; } } </script> Output: Check if a jquery has been loaded or not Example 2: The src attribute of script element is changed to sc. In this example, the JQuery is not loaded so message 'Script loaded successfully!' prints on screen after successful loading. html <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"> </script> <h1 style="color:green;"> GeeksforGeeks </h1> <p id="GFG_UP"> </p> <button onClick="GFG_Fun()"> click here </button> <p id="GFG_DOWN"> </p> <script> var up = document.getElementById('GFG_UP'); var down = document.getElementById('GFG_DOWN'); up.innerHTML = "Click on button to check whether JQuery is loaded"; function GFG_Fun() { if (!window.jQuery) { var el = document.createElement('script'); el.type = "text/javascript"; el.src = "https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"; document.getElementsByTagName( 'head')[0].appendChild(el); down.innerHTML = "Script loaded successfully!"; } else { down.innerHTML = "Script already loaded!"; } } </script> Output: Check if a jquery has been loaded or not Comment More infoAdvertise with us Next Article Check if a jquery has been loaded or not P PranchalKatiyar Follow Improve Article Tags : JQuery jQuery-Questions Similar Reads How to check if a jQuery plugin is loaded? There are multiple ways by which we can simply check whether the jQuery plugins are loaded successfully or not using jQuery. We can also check whether a particular function within the plugin is accessible or not. This tutorial will demonstrate how to check if a jQuery plugin is loaded or not. Step 1 3 min read How to load local jQuery file in case CDN is not available ? jQuery is a lightweight, "write less, do more" Â JavaScript library. Â jQuery helps to write JavaScript as simply as easily possible. It is effective in converting a few lines of code in JavaScript to one single line. Â It also simplifies tasks like Ajax calls and DOM (Document Object Model). The jQuer 3 min read How to check element exists or not in jQuery ? Checking if an element exists in jQuery involves selecting the element and verifying its length. If the selected element's length is greater than 0, the element exists in the DOM; otherwise, it doesn't. This is useful for conditionally manipulating elements. There are two ways to check whether an el 3 min read How to run a code on document ready event in jQuery ? In this article, we will see how to run a code when a page loads using jQuery. To run a code at page load time, we will use the ready() method. This method helps to load the whole page and then execute the rest code. This method specifies the function to execute when the DOM is fully loaded. Syntax: 1 min read jQuery callbacks.has() Method The callbacks.has() method in jQuery is used to answer whether the list has any callbacks attached. If a callback is passed as an argument, then it answers whether it is on the list or not. Syntax:callbacks.has([callback])Parameters:callback: The parameter defines the callback to search for, in the 2 min read Like