1
0
mirror of synced 2025-02-09 16:49:24 +03:00

explain the need to unbind events after calling destroy

This commit is contained in:
alexweissman 2017-10-12 11:12:59 -04:00
parent 7eef84ec1a
commit b746ddbd90

View File

@ -49,6 +49,26 @@ The `destroy` method will remove the Select2 widget from the target element. It
$('#mySelect2').select2('destroy');
```
### Event unbinding
When you destroy a Select2 control, Select2 will only unbind the events that were automatically bound by the plugin. Any events that you bind in your own code, **including any [Select2 events](/programmatic-control/events) that you explicitly bind,** will need to be unbound manually using the `.off` jQuery method:
```
// Set up a Select2 control
$('#example').select2();
// Bind an event
$('#example').on('select2:select', function (e) {
console.log('select event');
});
// Destroy Select2
$('#example').select2('destroy');
// Unbind the event
$('#example').off('select2:select');
```
## Examples
<div class="s2-example">