jQuery change() Method

jQuery change() method trigger the change event. The jQuery change event occurs when the value of an element has been changed. And when the change event occurs, specified function will execute.

The change() event is limited to <input>, <textarea>, and <select> elements.

Syntax

This syntax represent to the change event trigger

$(selector).change();        // This syntax does not accept any arguments.

and this syntax represent to attach a function to the change event

$(selector).change(function);
Parameter Type Description
function Function Optional. Specifies the function to execute when the event is occurs for the selected elements.

Examples

This example represent the triggers the change event for selected elements.

$(document).ready(function(){
  $("button").click(function(){
    $("input").change();
  });
  $("input").change(function(){
    $value = $(this).val()
    $(this).css("background-color", "#81fb81");
    $("span").text($value);
  });
});

Run it...   »


This example represent to adds a function to the change event.

$(document).ready(function(){
  $("input").change(function(){
    $(this).css("background-color", "#81fb81");
  });
});

Run it...   »