Skip to main content

Bug Tracker

Side navigation

#8742 closed bug (invalid)

Opened April 01, 2011 02:08PM UTC

Closed April 01, 2011 03:11PM UTC

Uncaught TypeError when calling $.extend on a click event object

Reported by: peterson@devnetinc.com Owned by:
Priority: undecided Milestone: 1.next
Component: unfiled Version: 1.5.2
Keywords: Cc:
Blocked by: Blocking:
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>
Attachments (0)
Change History (2)

Changed April 01, 2011 02:12PM UTC by peterson@devnetinc.com comment:1

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

Changed April 01, 2011 03:11PM UTC by timmywil comment:2

resolution: → invalid
status: newclosed
version: 1.5.11.5.2

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/