jQuery change() with callback function

Introduction

Alert a text when an <input> field is changed:

Write something in the input field, and then press enter or click outside the field.

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>/*from  www .  ja v  a2 s  .c  om*/
<script>
$(document).ready(function(){
  $("input").change(function(){
    document.getElementById("demo").innerHTML = 
              "The text has been changed.";
  });
});
</script>
</head>
<body>

<p id="demo"></p>
<input type="text">

</body>
</html>



PreviousNext

Related