Open In App

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. 

npm install -g browser-sync




<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JQuery Plugin</title>
    <script src=
    </script>
</head>
<body>
    <div>Hello GeeksForGeeks</div>
    <script type="text/javascript">
        $(document).ready(function () {
            if (typeof $.ui !== 'undefined') {
                console.log('jquery-ui is loaded successfully')
            }        
        });
    </script>
    <script src="jquery-ui-1.12.1/jquery-ui.js"
            type="text/javascript"></script>
</body>
</html>

Example 2: Since every plugin is guaranteed to have some function definitions or values that equate to true, we can use the shorter version as shown in the code. 






if ($.ui) {
    console.log('jquery-ui is loaded successfully')
}




<script type="text/javascript">
$(document).ready(function () {
    if (typeof $.fn.pluginname !== 'undefined') {
        console.log('jquery-ui is loaded - 2')
    }
    if ($.fn.pluginname) {
        console.log('jquery-ui is loaded - 3')
    }
});
</script>




<input type="text" name="date" id="date">
<script type="text/javascript">
   $(document).ready(function () {
       if (jQuery().datepicker()) {
          console.log('jquery-ui datepicker() function is accessible')
       }
       if (typeof $.fn.datepicker() !== 'undefined') {
           console.log('jquery-ui datepicker() function is accessible')
       }
       if ($.fn.datepicker()) {
           console.log('jquery-ui datepicker() function is accessible')
       }  
       $("#date").datepicker();
   });
</script>

browser-sync start --server --files "*"

This starts Browsersync in server mode and watches all the files within the directory for changes as specified by the * wildcard. The application will be launched at http://localhost:3000/ by default.

Output: 




Article Tags :