jQuery change event


 

jQuery change event

In this tutorial , we will discuss about 'change' event of jQuery.

In this tutorial , we will discuss about 'change' event of jQuery.

jQuery change event

In this tutorial , we will discuss about 'change' event of jQuery. In given below example ,the change event is fired when there is change in the element (on which event is set).When the second option is selected from the dropdown, the alert is displayed. It is also displayed if we change the text in the field and then click away.

formChange.html

<!DOCTYPE html>
<html>
<head>
<script src="jquery-1.4.2.js"></script>
</head>
<body>
<form>
<input class="flag" type="text" value="Input Field" />
<select class="flag">
<option value="option1" selected="selected">First Option</option>
<option value="option2">Second Option</option>
</select>
</form>
<div id="other">
Select second option or edit first input field to trigger the alert box.
</div>
<script>
$('.flag').change(function() {
alert('Change method is trigerred');
});
</script>
</body>
</html>

OUTPUT

When we edit input field :

When we select second option :

Download Source Code

Click here to see demo

Ads