2

How can I remove a function from a jquery object? For example, I have

$('#element').func = function() {
     // function body goes here
}

And later on I want to remove func from $('#element'). I've tried delete but it doesn't work. Thanks.

Lim H.
  • 9,870
  • 9
  • 48
  • 74

2 Answers2

9

How about this?

$('#element').fn.func = null;

or

$('#element').prototype.func = null;

or

delete $('#element').fn.func;

or

delete $('#element').prototype.func;

For understanding what the prototype is, have a look here: How does JavaScript .prototype work?

Community
  • 1
  • 1
Marvin Emil Brach
  • 3,984
  • 1
  • 32
  • 62
1

you can do by assigning null.

$('#element').fn.func = null;
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307