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,514
  • 9
  • 46
  • 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,925
  • 1
  • 29
  • 61
1

you can do by assigning null.

$('#element').fn.func = null;
Suresh Atta
  • 118,038
  • 37
  • 189
  • 297