Javascript examples for jQuery Method and Property:change
The change() method triggers the change event, or sets a function as change event handler for <input>, <textarea> and <select> elements.
$(selector).change(function);
Parameter | Description |
---|---|
function | Optional. Specifies the function to run when the change event occurs for the selected elements |
The following code shows how to Alert a text when an <input> field is changed:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("input").change(function(){ console.log("The text has been changed."); });//ww w. j a va 2s . co m }); </script> </head> <body> <input type="text"> <p>Write something in the input field, and then press enter or click outside the field.</p> </body> </html>