Alex
Alex

Reputation: 68074

unattach a jQuery function from a element

is this possible?

Like when you have a lightbox plugin: $('.foo').lightbox()

Can you remove lightbox() from all .foo's, or only from specific a .foo ?

Upvotes: 0

Views: 623

Answers (3)

Tristian
Tristian

Reputation: 3512

You might find this interesting Unbinding Plugins

Upvotes: 2

David Fells
David Fells

Reputation: 6798

You can do it two ways. One is to remove it from $ altogether - probably not what you want - by doing

$.lightbox = null;

If you want to do it to a set of elements, you would need to do this:

var elements = $('.foo');
elements.lightbox = null;

Note that this won't remove that function from subsequent calls to $, as that will generate a fresh jQuery object w/ all available plugins when you call it.

Upvotes: 2

Demian Brecht
Demian Brecht

Reputation: 21378

The selector applies to all instances.

Upvotes: 1

Related Questions