I have the following jquery binding to listen for paste action in certain text input elements. Is there a way inside of the function to get a reference to the actual element that triggered the event? My goal is to clear out the text in the input if anything is pasted inside out it, but 'this' doesn't seem to be correct.
Edit, the code has been updated:
$(window).on("load", function() {
$('.watchable').bind("paste", function() {
alert('called!');
$(this).val('');
});
});
I am using JQuery 1.11.3. I see the alert, but the text is not cleared out.
Here is a jsFiddle demo. Paste any text into either of the 2 text fields, the alert displays, but the text in the text field is not cleared out.
.on()method is the preferred method for attaching event handlers to a document.