Jquery Onchange Example - Jquery

How to use onchange event in jquery?

Snippet Code


  
Rate this page :
  [ 0 votes]

Jquery onchange is an event handler which is executed when the value of an element has been changed. Here the simple jquery onchange code to change the background colorby selecting an item is given below.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script> <script> $(function() { $('select').change(function() { var color = $("#myselect option:selected" ).text() $('body').css("background",color); }); }); </script> <div align='center'> <b>Choose Background Color :</b> <select id='myselect'> <option>lightgreen</option> <option>lightblue</option> <option>cyan</option> <option>pink</option> </select> </div>

Tags


Ask Questions

Ask Question