Ticket #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: | |
| Blocking: | Blocked by: |
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.
Change History
comment:1 Changed 2 years ago by addyosmani
- Owner set to anonymous
- Priority changed from undecided to low
- Status changed from new to pending
- Component changed from unfiled to attributes
comment:4 Changed 2 years ago by timmywil
- Cc timmywil removed
- Priority changed from undecided to low
- Status changed from pending to open
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).
comment:5 Changed 2 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 2 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 2 years ago by addyosmani
- Keywords neededdocs added; needsdocs removed
Docs updated: http://api.jquery.com/removeAttr/
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

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.