django
django

Reputation: 2909

jQuery off().remove() or .remove().off() performance

I read different answers on stackoverflow on how can I destroy a wigdet/jQueryObject and unbind all events on it.

And here is what I came up with.

  1. $('selector').remove().off().find("*").off();
  2. $('selector').off().remove().find("*").off();

Question: My question is regarding the performance of above 2. Will there be a performance difference by changing the order. Is there a difference between using off() after remove() or before remove()? Or is it the same and the order is not important, performance wise?

Update :

also what about Empty

  1. $('selector').empty().off().find("*").off();
  2. $('selector').off().empty().find("*").off();

Upvotes: 0

Views: 317

Answers (1)

adeneo
adeneo

Reputation: 318312

There's no need to do that at all, the documentation for remove() states

In addition to the elements themselves, all bound events and jQuery data associated with the elements are removed.

so all you need is

$('selector').remove();

Upvotes: 5

Related Questions