Share on Google+Share on Google+

jQuery change event

Ads
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

Advertisements

Ads

Posted on: July 29, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Ads

Advertisement