Bug Tracker

Modify

Ticket #9405 (closed bug: patchwelcome)

Opened 2 years ago

Last modified 2 years ago

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

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 2 years ago by rwaldron

  • Cc timmywil added

comment:3 Changed 2 years ago by rwaldron

  • Priority changed from low to undecided

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

comment:8 Changed 2 years ago by timmywil

  • Status changed from open to closed
  • Resolution set to patchwelcome

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.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.