Reputation: 2538
I add and remove classes dynamicaly. But when I remove class the event still working. How to stop event to work.
$('.input').on('paste keypress, keydown', function(event) {
fff();
})
But as soon as I add the class I need it to work.
Upvotes: 0
Views: 70
Reputation: 1392
In case you can not add a static class to parent you can remove the assigned events after removing the class like below
javascript
function fff() {
alert('chacha!!');
}
$(function() {
$('#removeClass').on('click', function() {
$('.input').removeClass('input').off('paste keypress, keydown');
});
$('.input').on('paste keypress, keydown', function(event) {
fff();
})
});
Hope it works for you
Upvotes: 1
Reputation: 148150
Use event delegation and bind event with static parent.
$('.static-parent-class').on('paste keypress, keydown', '.input', function(event) {
fff();
});
Upvotes: 2