Jquery Datatable Add Css To Cell After Update
I am trying to add CSS to a cell after a record in my jQuery Datatable is updated. Basically to show the user that the update was successful. I'm using a BLUR event to send the par
Solution 1:
It thinks its better to use event delegation for listening events of dynamic elements instead of binding event handler each time.
Where you can check value is changed or not by comparing current value with the value
attribute.
$('#example1').on('blur', 'tr > td > .editForecast', function(){
// check value is changed or notif(this.value !== $(this).attr('value')){
$(this).css('background-color', 'green');
}
});
Or better way would be tracking the current value while focusing the element(using event delegation) and later compare with the tracked value.
// list focus event to track the current value of element
$('#example1').on('focus', 'tr > td > .editForecast', function(){
$(this).data('value', this.value);
})
$('#example1').on('blur', 'tr > td > .editForecast', function(){
// compare value with the tracked valueif(this.value !== $(this).data('value')){
$(this).css('background-color', 'green');
}
});
Solution 2:
For the first event, why not use onFocus(), then use onBlur() for the second event.
Post a Comment for "Jquery Datatable Add Css To Cell After Update"