New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delegated click handler is not called when non-button target is disabled #3664

Closed
russplaysguitar opened this Issue May 8, 2017 · 4 comments

Comments

Projects
None yet
3 participants
@russplaysguitar

russplaysguitar commented May 8, 2017

Description

If a non-button target element of a delegated click handler is disabled by $.prop(), the handler is not called. I expected the handler to be called because the element does not support the disabled attribute,

Reproduced the issue in Chrome and Firefox.

I believe that this is the problematic line: https://github.com/jquery/jquery/blob/master/src/event.js#L382

Example:

<!--- html --->
<a id="link" href="#">click me twice</a>
// js
$(document).ready(function() {
  $('body').on('click', '#link', function() {
    alert('clicked');
    $('#link').prop('disabled', true);
  });
});

Link to test case

jQuery: https://codepen.io/anon/pen/KmZaOp?editors=1010
Zepto: https://codepen.io/anon/pen/rmpyBW?editors=1010 (for comparison)

@dmethvin

This comment has been minimized.

Show comment
Hide comment
@dmethvin

dmethvin May 9, 2017

Member

I looked about a year ago and browsers still weren't consistent about propagating clicks on disabled buttons/links. You can see all the ticket references there. Is there a reason why you're setting a property on elements that has a defined meaning on other elements? Did you just happen to pick that name because it was short and meaningful for your custom need?

Member

dmethvin commented May 9, 2017

I looked about a year ago and browsers still weren't consistent about propagating clicks on disabled buttons/links. You can see all the ticket references there. Is there a reason why you're setting a property on elements that has a defined meaning on other elements? Did you just happen to pick that name because it was short and meaningful for your custom need?

@russplaysguitar

This comment has been minimized.

Show comment
Hide comment
@russplaysguitar

russplaysguitar May 11, 2017

I set the disabled property on some links out of habit (since it works on buttons). Only afterwards did I realize that it shouldn't disable the click handler, since the property is not supported on links. This is certainly not a critical issue for me, I just make it a habit to report potential bugs to open source projects that I use.

I set the disabled property on some links out of habit (since it works on buttons). Only afterwards did I realize that it shouldn't disable the click handler, since the property is not supported on links. This is certainly not a critical issue for me, I just make it a habit to report potential bugs to open source projects that I use.

@timmywil

This comment has been minimized.

Show comment
Hide comment
@timmywil

timmywil May 15, 2017

Member

We talked it over and there are so many things you can break with invalid HTML. We deemed the possible solutions here not worth it.

Member

timmywil commented May 15, 2017

We talked it over and there are so many things you can break with invalid HTML. We deemed the possible solutions here not worth it.

@timmywil timmywil closed this May 15, 2017

@russplaysguitar

This comment has been minimized.

Show comment
Hide comment
@russplaysguitar

russplaysguitar May 15, 2017

That's fine, thanks for considering it. I just thought I might as well get this situation documented in case anyone else runs into it.

That's fine, thanks for considering it. I just thought I might as well get this situation documented in case anyone else runs into it.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 18, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.