I have a simple past event as
document.getElementById('paste_area').addEventListener('paste', function() {
document.getElementById('notice').innerHTML='Text was successfully pasted!';
alert('Pasted');
}, true);
A working example can be found here http://jsfiddle.net/XEQzz/
The alert and notice will appear before pasting. How can I delay the alert action to happen after paste event has been actually completed?
You could put your alert in a
setTimeout.This will delay the code until after the value has updated.
Just keep in mind that
thisin thesetTimeoutcallback will have a different value than that in the enclosing environment.If you’ll need a reference to the outer
this, which will be the element, then reference it in a variable…Or use
.bind()(Supported in most browsers that supportaddEventListener. Older Safari didn’t support it.)…