Check if jQuery is Loaded Script

Glenn Blog Leave a Comment

jQuery is a fast, small, and feature-rich JavaScript library and we use it extensively across all our sites. A key factor when developing is that the library is correctly loaded, but also that it’s only loaded once. To check if jQuery is already loaded into your platform (i.e. WordPress has it by default) then you can use this Javascript snippet:-

<script>
  window.onload = function() {
    if (window.jQuery) {  
        // jQuery is loaded  
        alert("jQuery is loaded!");
    } else {
        // jQuery is not loaded
        alert("jQuery is not loaded");
    }
}
</script>

If jQuery is present then you will see an alert with “jQuery is loaded!” and if it’s not then ‘jQuery is not loaded’.

How to add jQuery to your site

If jQuery is Not Loaded then simply add the code just before

</body>

or less favourably between the

<head></head>

From Google’s Hosted Libraries:-

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
About the Author
Check if jQuery is Loaded Script 0da77002febbfe28d15144a57bbcc2c9 s 180 d mm r g

Glenn

A highly experienced Web Designer / Web Developer (Webflow, WordPress, Weebly & Custom), Front-end / Back-end Developer & New Media Specialist, with extensive knowledge of a wide spectrum of technologies in the Development and Creative Industries, built up over a number of years.