How to check if a plugin function exists?

I have this code:

$(document).ready(function() {
    $('.tabs-container').tabs({ 
        tabs: '.bar', 
        tabs_container: '.foo' 
    });
});

      

Sometimes the tabs script plugin won't load, causing the rest of the js page to abort due to this error in the console:

TypeError: $(...).tabs is not a function

      

How can I check if a tab function exists before attaching this plugin to an element?

+3


source to share


1 answer


if($.fn.tabs) {
    /// .. it exists
}

      



+10


source







All Articles