Skip to main content

Bug Tracker

Side navigation

#9405 closed bug (patchwelcome)

Opened May 23, 2011 09:42AM UTC

Closed June 07, 2011 11:45PM UTC

Removal of "onclick" inline event handler seems to require different code for IE9

Reported by: anonymous Owned by: anonymous
Priority: low Milestone: 1.next
Component: attributes Version: 1.6.1
Keywords: neededdocs Cc:
Blocked by: Blocking:
Description

When trying to remove an "onclick" inline event handler, using removeAttr('onclick') seemed to work in all browsers except for IE9, for which I had to use removeProp('onclick').

removeProp('onclick') also worked in Chrome 11, FF 3.6 and probably also older/newer version of those browsers, but not in IE6/7/8.

So I have to use both methods to get rid of the "onclick" in all browsers.

Attachments (0)
Change History (8)

Changed May 23, 2011 12:52PM UTC by addyosmani comment:1

component: unfiledattributes
owner: → anonymous
priority: undecidedlow
status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a reduced test case on http://jsFiddle.net that reproduces the issue experienced to help us assess your ticket!

Additionally, test against the jQuery (edge) version to ensure the issue still exists.

Changed May 23, 2011 01:30PM UTC by rwaldron comment:2

cc: → timmywil

Changed May 23, 2011 01:31PM UTC by rwaldron comment:3

priority: lowundecided

Changed May 23, 2011 02:46PM UTC by timmywil comment:4

cc: timmywil
priority: undecidedlow
status: pendingopen

It seems this is valid. The attribute is getting removed, but does not have the expected side effects. IE9 does not clear the property when the attribute is removed, even though other browsers do (including IE6-8).

http://jsfiddle.net/timmywil/2hayU/

For now, do not use removeProp on native properties. To remove the handler, you can do .prop("onclick", null).

Changed May 23, 2011 03:55PM UTC by anonymous comment:5

Thanks a lot for verifying this and also for the workaround, timmywil. I tried several ways of using attr and prop to get around this, but not setting the property to null.

Changed May 24, 2011 01:06PM UTC by dmethvin comment:6

keywords: → needsdocs

Since we advise against inline handlers anyway, perhaps timmywil's solution can just be documented as the standard cross-browser way to do this? To me it's not worth putting in special code to allow several other ways.

Changed June 05, 2011 08:39PM UTC by addyosmani comment:7

keywords: needsdocsneededdocs

Changed June 07, 2011 11:45PM UTC by timmywil comment:8

resolution: → patchwelcome
status: openclosed

I don't think we're going to be able to bring ourselves to add the special code to take care of this in attr, but I think we would consider patches if short enough.