Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove function from a jquery object

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.

like image 860
Lim H. Avatar asked Jul 04 '26 22:07

Lim H.


2 Answers

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?

like image 137
Marvin Emil Brach Avatar answered Jul 07 '26 13:07

Marvin Emil Brach


you can do by assigning null.

$('#element').fn.func = null;
like image 24
Suresh Atta Avatar answered Jul 07 '26 13:07

Suresh Atta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!