Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A paste event triggered manually has no .originalEvent property?

Tags:

jquery

When I trigger a paste event with .trigger(), the ensuing captured paste event has no .originalEvent property. Is this expected behavior? Why?

See example - http://jsfiddle.net/2uxEr/

<textarea>Paste something here</textarea>
<button>Click for fake trigger</button>

$('textarea').on("paste", function(e){

     alert(e.hasOwnProperty("originalEvent"));

});

$('button').click(function(){

    $('textarea').trigger("paste");

});
like image 930
HyShai Avatar asked Mar 03 '13 16:03

HyShai


1 Answers

jQuery events will not have an originalEvent property if they were triggered manually. How could they? The originalEvent is the event object created by the browser from which jQuery formed its event object; in a manually triggered event, jQuery created the event object itself. There is no originalEvent to access.

This jsFiddle example shows how this is true for events like click as well as paste.

like image 182
lonesomeday Avatar answered Dec 09 '22 00:12

lonesomeday