Is it possible to click on a disabled button and provide some feedback to the user?
HTML:
<input type="button" value="click" disabled>
and JavaScript:
$('input').mousedown(function(event) {
alert('CLICKED');
});
The above code is not working for me; neither is this:
$('input').live('click', function () {
alert('CLICKED');
});
Making the field
readonly
can help, because the click event will be fired. Though be aware of the differences in behaviour.What about wraping the button in some element and catching click on this element instead?
Javascript:
There is no way to capture a click on disabled elements. Your best bet is to react to a specific
class
on the element.HTML Markup:
JavaScript code:
You could then use CSS styling to simulate a disabled look:
Here's a jsFiddle demonstrating its use.
you can't click on disabled button, but can click on disabled link
Put
in your CSS (it prevents some browsers from discarding clicks on disabled inputs altogether), and capture the click on a parent element. It's a cleaner solution, IMHO, than putting a transparent overlay over the element to capture the click, and depending on circumstances may also be much easier than simply "simulating" the disabled state using CSS (since that won't prevent the input from being submitted, and also requires overriding the default browser 'disabled' style).
If you have multiple such buttons, you'll need a unique parent for each, in order to be able to distinguish which button was clicked, because with
pointer-events:none
, the click target is the button's parent rather than the button itself. (Or you could test the click coordinates, I suppose...).If you need to support older browsers, though, do check which ones support
pointer-events
: http://caniuse.com/#search=pointer-eventsYou can't without a workaround, see: jQuery detect click on disabled submit button
The browsers disable events on disabled elements.
Edited to add context from link:
The asker found this thread with an explanation of why the events aren't registering: http://www.webdeveloper.com/forum/showthread.php?t=186057
The workaround would be style the button to "look" disabled, while not actually being so.