labas GamePage visogero labas GamePage visogero - 4 months ago 13
jQuery Question

jQuery removeClass from button

I need to remove "disabled" class from button when there is at least one char in the input. This is jQuery code:

$('.reply').on('change', function() {
if ($(this).val().length > 0) {
$(".replyBtn").removeClass('disabled');
}
});


This is HTML:

<input type="text" name="reply" class="reply form-control" placeholder="Rašykite atsakymą...">
<br>
<button type="submit" class="replyBtn btn btn-success disabled">Atsakyti</button>


But it's not working and I don't get errors in console

Answer

$('.reply').on('input', function() {
  if ($(this).val().length > 0) {
    $(".replyBtn").removeClass('disabled');
  } else {
    $(".replyBtn").addClass('disabled');
  }
});
.disabled {
  color: red
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" name="reply" class="reply form-control" placeholder="Rašykite atsakymą...">
<br>
<button type="submit" class="replyBtn btn btn-success disabled">Atsakyti</button>

Use input