Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clicking a disabled input or button

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'); }); 
like image 716
e1761587 Avatar asked Apr 19 '13 16:04

e1761587


People also ask

How do I make a disabled button clickable?

Answer. Swap your disabled attribute for aria-disabled="true" . This will allow the element to maintain most of its properties that allow you to interact with it, but still keep its disabled status and announce itself to assistive technology as such.

What is disabled in button?

The disabled attribute is a boolean attribute. When present, it specifies that the button should be disabled. A disabled button is unusable and un-clickable. The disabled attribute can be set to keep a user from clicking on the button until some other condition has been met (like selecting a checkbox, etc.).


2 Answers

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:

<input type="button" class="disabled" value="click" /> 

JavaScript code:

$('input').click(function (event) {     if ($(this).hasClass('disabled')) {         alert('CLICKED, BUT DISABLED!!');     } else {         alert('Not disabled. =)');     } }); 

You could then use CSS styling to simulate a disabled look:

.disabled {     background-color: #DDD;     color: #999; } 

Here's a jsFiddle demonstrating its use.

like image 177
Jesse Avatar answered Sep 24 '22 03:09

Jesse


Making the field readonly can help, because the click event will be fired. Though be aware of the differences in behaviour.

<input type="button" value="click" readonly="readonly" /> 
like image 27
Dennis Golomazov Avatar answered Sep 22 '22 03:09

Dennis Golomazov