Kjensen
Kjensen

Reputation: 12384

How do I check if a jquery plugin is already initialized on a jquery element?

This is code to destroy and initialize a jquery plugin cubeportfolio (I don't think this is specific to cubeportfolio).

jQuery('#some-grid').cubeportfolio('destroy');

jQuery('#some-grid').cubeportfolio(options);

If I want to re-initialize it, I first need to destroy it, which works fine if it already exists.

But I get an error if I try to destroy an instance, that does not already exists (which makes complete sense).

How can I check if cubeportfolio is already initialized on #some-grid?

Upvotes: 1

Views: 624

Answers (1)

AvcS
AvcS

Reputation: 2323

You can use

Boolean($('#some-grid').data('cubeportfolio'))

to check if an instance of cubportfolio already exists on the given element

Upvotes: 2

Related Questions