Bug Tracker

Opened 8 years ago

Closed 8 years ago

#7633 closed bug (invalid)

$.attr('onclick', 'somefunction()') not working on Google Chrome

Reported by: yajo Owned by:
Priority: undecided Milestone: 1.5
Component: unfiled Version: 1.4.4
Keywords: Cc:
Blocked by: Blocking:

Description

I noticed this bug. In Firefox it works. Using FF 3.6 and GC 7.

Change History (1)

comment:1 Changed 8 years ago by jitter

Resolution: invalid
Status: newclosed

Thanks for taking the time to contribute to the jQuery project by writing a bug report!

After checking what you reported I conclude that this isn't a jQuery bug. What you are doing is also very uncommon and the correct jQuery way to do this would be to use $(selector).bind("click", somefunction) (as this is guaranteed to work cross-browser).


But it probably also isn't a bug in Chrome.

I made this test case during checking on your problem. As you can see all buttons but "Click me 4" work in Chrome.

To understand this you need to know that attr(name, value) doesn't set the HTML attribute but uses the DOM property and it looks like Chrome (rightfully) doesn't allow setting the onclick DOM property to a string but only to a function. Other browsers are less strict about this and automagically convert a string assignment into a function. Chrome doesn't.

attr(name, value) using the DOM property also explains why "Click me 7" works but "Click me 4" doesn't, as for "Click me 7" I set the HTML attribute directly and in this case (as when done inline) Chrome converts the value to a function call.

So basically you have just hit a "rough" (or better differing) point in Chrome's DOM implementation. If you understood all of the above and still feel this is a bug then feel free to report this on the Chrome bug tracker.

Note: See TracTickets for help on using tickets.