I have following HTML snippet for a button:
HTML:
<div class="Clear" title="Clear">
<div class="ClearButton">
<button id="reset" type="reset" title="Clear Photos"></button>
</div>
<div class="ClearText">
Clear
</div>
</div>
CSS:
div.ClearButton
{
vertical-align: top;
display: inline-block;
background: url(../CustomControl/buttons.png?ver=365321878) no-repeat scroll -343px -443px rgba(0, 0, 0, 0);
height: 16px;
overflow: hidden;
width: 16px;
}
div.Clear
{
vertical-align: top;
display: inline-block;
overflow: hidden;
cursor: pointer;
padding-left: 2px;
padding-bottom: 6px;
padding-right: 6px;
padding-top: 4px;
}
On a certain event, I need to disable this button completely. I tried with the following code, but it does not disable/gray out the button and it's still clickable.
var resetBtn = document.getElementById("reset");
resetBtn.disabled = true;
As someone suggested that the CSS I have applied is causing this issue. Please suggest how can I make this button non-clickable.
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.).
To disable a button using only JavaScript you need to set its disabled property to false . For example: element. disabled = true . And to enable a button we would do the opposite by setting the disabled JavaScript property to false .
ready(function() { $('input[type="button"]'). click(function() { var input = this; input. disabled = true; setTimeout(function() { input. disabled = false; }, 3000); }); });
Use :
resetBtn.disabled = "disabled";
This works in all browsers -> http://jsfiddle.net/fMV4B/
Using Only CSS:
//CSS
.no-click {pointer-events: none;}
<input class="no-click" />
You can do it with the method : setAttribute()
Your js will be like that :
document.getElementById("reset").setAttribute('disabled','disabled');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With