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: |
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 (8)
comment:1 Changed 12 years ago by
Component: | unfiled → attributes |
---|---|
Owner: | set to anonymous |
Priority: | undecided → low |
Status: | new → pending |
comment:2 Changed 12 years ago by
Cc: | timmywil added |
---|
comment:3 Changed 12 years ago by
Priority: | low → undecided |
---|
comment:4 Changed 12 years ago by
Cc: | timmywil removed |
---|---|
Priority: | undecided → low |
Status: | pending → 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 12 years ago by
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
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
Keywords: | neededdocs added; needsdocs removed |
---|
Docs updated: http://api.jquery.com/removeAttr/
comment:8 Changed 12 years ago by
Resolution: | → patchwelcome |
---|---|
Status: | open → closed |
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.
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.