Computers & ProgrammingFrontend DevelopmentjQuery

jQuery Change Event

The jQuery event change() method is triggered when the value of an element is changed. This method works on text fields, text areas, and select elements. The change() method triggers the change event, or can specify a function to run when a change event occurs.

For select elements, the change event is triggered when an option is selected from the dropdown list. For text fields and text areas, the change event is triggered when the field loses focus.

Syntax

$(selector).change()
$(selector).change(function)
ParameterDescription
functionOptional. Function to run when the event occurs.

Example

$("input").change(function () {
    $(this).css("background-color", "#999999");
});

In the jQuery code listed above, the change() method specifies that a function should run when the change event occurs.

Leave a Comment

Your email address will not be published.

Scroll to Top