javascript - Select2 off('change').on('change'.....) does not able to change the selected option -


i use select2-4.0.0 and

$gameselect.select2().on("change",function(e){....} 

works fine.

but when chain following off('change') like:

$gameselect.select2().off('change').on("change",function(e){....} 

the event triggered selected item not change @ ui.

why that?

looks select2-4.0 adding own change handlers select element, when off('change') getting removed reason.

to fix kind of problems have event name spacing so, use namespace handlers , use remove them like

$('#my-select').select2().off('change.mychange').on('change.mychange', function () {     //your code }); 

demo: fiddle


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -