Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
158
rated 0 times [  164] [ 6]  / answers: 1 / hits: 28893  / 11 Years ago, sun, october 27, 2013, 12:00:00

Can someone help me understand the use of originalEvent in JavaScript? I really can't find a good source of documentation about it.



Google results led me to discussion sites that were too complicated to understand for a newbie.



I recently had a question in SO, and a guy answered it by adding this line of code



$(#url).bind('paste', function(e) {
var val = e.originalEvent.clipboardData.getData('text/plain');
....


to my existing code, which worked btw.



I would greatly appreciate if someone can help me understand the use of it.


More From » jquery

 Answers
6

You are using a JavaScript library called jQuery, which is where the $() function comes from. jQuery wraps several parts of JavaScript to make it easier to use. One of those parts is event handling. In your example, because you're using jQuery to bind to the paste event, the object passed to your callback (e) is a jQuery event object, not a built-in JavaScript event object. The jQuery event object exposes the originalEvent property to give you access to the underlying built-in event object.



In your example you need to get hold of the clipboard data, which isn't available through the jQuery event object so you need to access the original event object to get at it.


[#74706] Friday, October 25, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kenandwightb

Total Points: 241
Total Questions: 95
Total Answers: 111

Location: Jersey
Member since Fri, Oct 1, 2021
3 Years ago
;