JSFiddle - React, Tailwind, and code Playground
HTML
<div class="order-element">
<div class="input">
<label for="target">Test</label>
<input disabled="disabled" type="text" class="target" />
<div class="control normal"></div>
</div>
</div>
CSS
.input{
width: 160px;
}
.normal{
width: 16px;
height: 16px;
background: red;
float: right;
}
.checked{
background: green;
float:right;
}
input[disabled]{
background: #F7F7F7;
}
JavaScript
$(document).ready(function() {
$(".control").toggle(
function() {
$('.target').removeAttr("disabled");
$(this).addClass("checked");
alert('You pressed the red div');
}, function() {
$('.target').attr("disabled", true);
$(this).removeClass("checked");
alert('You pressed the green div');
});
$('input').keypress(function(event) {
var keycode = (event.keyCode ? event.keyCode : event.which);
if (keycode == '13') {
$('.target').attr("disabled", true);
$('.control').removeClass("checked");
alert('You pressed a "enter" key in textbox');
return false;
}
});
});