user967451
user967451

Reputation:

How to check if a plugin's function exists?

I have this code:

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

Sometimes the tabs plugin script isn't loaded which causes the rest of the page's js to break due to this error in the console:

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

How can I check to see if tabs function exists before attaching that plugin to an element?

Upvotes: 3

Views: 173

Answers (1)

Russ Cam
Russ Cam

Reputation: 125538

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

Upvotes: 9

Related Questions