Ticket #8742 (closed bug: invalid)
Uncaught TypeError when calling $.extend on a click event object
| Reported by: | peterson@… | Owned by: | |
|---|---|---|---|
| Priority: | undecided | Milestone: | 1.next |
| Component: | unfiled | Version: | 1.5.2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
I'm capturing mouse clicks on my page by binding the click event of the body element. I'm wrapping up information about the event and storing it as JSON, using $.extend to perform a deep copy of the event object.
If I click an input element (in my case a radio button), $.extend then loops through the click event object and gets this error: Uncaught TypeError: Accessing selectionEnd on an input element that cannot have a selection.
I've attached a quick and dirty example based off what I'm doing:
$("body").click(function(eventData) {
var click = {
X: eventData.pageX,
Y: eventData.pageY,
timestamp: (new Date).getTime(),
target: $.extend(true, {}, eventData.target)
};
});
<html><body><form><input type="radio"></form></body></html>
Change History
comment:2 Changed 2 years ago by timmywil
- Status changed from new to closed
- Version changed from 1.5.1 to 1.5.2
- Resolution set to invalid
You should not be using $.extend on a node. It is meant for merging plain objects and nodes cannot always be treated as such. To make copies of nodes, use http://api.jquery.com/clone/
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Sorry, here's a jsFiddle example: http://jsfiddle.net/U9JCZ/