Bug Tracker

Opened 12 years ago

Closed 12 years ago

#9405 closed bug (patchwelcome)

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:


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.

Change History (8)

comment:1 Changed 12 years ago by addyosmani

Component: unfiledattributes
Owner: set to 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.

comment:2 Changed 12 years ago by Rick Waldron

Cc: timmywil added

comment:3 Changed 12 years ago by Rick Waldron

Priority: lowundecided

comment:4 Changed 12 years ago by timmywil

Cc: timmywil removed
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).


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

comment:5 Changed 12 years ago by anonymous

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.

comment:6 Changed 12 years ago by dmethvin

Keywords: needsdocs added

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.

comment:7 Changed 12 years ago by addyosmani

Keywords: neededdocs added; needsdocs removed

comment:8 Changed 12 years ago by timmywil

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.

Note: See TracTickets for help on using tickets.