1

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">

1 Answer 1

7

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">

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.