Alexander  Tolkachev
Alexander Tolkachev

Reputation: 227

Monitoring input field change jquery

How to detect whent i increment/decrement input value? The following code does not work for me(Using jquery 1.8)

$(document).ready(function(){
      $("input[id=count]").change(function(){
        alert($(this).val());
      });
    });
<input type="number" id="count" value="1">

Upvotes: 1

Views: 749

Answers (1)

Rayon
Rayon

Reputation: 36609

Use input event using .on method.

The DOM input event is fired synchronously when the value of an <input> or <textarea> element is changed.

change event on input type number/text is invoked when focus of the element is lost

Note: $("#count") is more appropriate selector(ID selector) than using Attribute Equals Selector [name=”value”] selector

$(document).ready(function() {
  $("#count").on('input', function() {
    console.log($(this).val());
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<input type="number" id="count" value="1">

Upvotes: 7

Related Questions