I have an asp.net UserControl that can be added multiple times to a page. On this UserControl I am using a jQuery plugin that I would only like to load once. I am using the following piece of code to conditionally load jQuery itself:
if (typeof jQuery == 'undefined') {
// load jquery
var script = document.createElement('script');
script.type = "text/javascript";
script.src = "/_layouts/SprocketValidator/jQuery.js";
document.getElementsByTagName('head')[0].appendChild(script);
} else {
//already loaded
}
Would there be an equivalent for checking if a jQuery plugin is undefined? The plugin I am using is the digitalBush masked input plugin.
Try:
jquery-methods (plugin-methods usually too) are stored as properties of
$.fn, so you’ll need to check if a method available inside the plugin(e.g.mask()) is known as member of$.fn