Javascript Ajax jQuery Html PHP Example Quiz New MORE

Disable enable input field in jQuery


In this example i am going to discuss how to disable enable input field in jQuery with simple example.

Example:1

<!DOCTYPE html>
<html>
<head>
<style>
.grey{
background-color:grey;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<input id="item_price" class="grey" value="100.00" disabled="disabled" />
<br>
<br>
<input type="button" id="Button" value="disable/enable" />
<script>
$(document).ready(function(){
$("#Button").click(function() {
$("#item_price").attr('disabled', !$("#item_price").attr('disabled'));
$("#item_price").removeClass("grey");
});
});
</script>
</body>
</html>

Run it yourself

Demo