.change() Event

.change() Event

  • Attaches an event handler function to the <input>, <textarea> and <select> elements that is executed when its value changes

Example

  • The following example will display an alert message when you select any option in dropdown select box
$('select').change((event) => {
  const selectedOption = $(event.currentTarget).find(':selected').val()

  alert(`You have selected ${$selectedOption}`)
})

JS Bin on jsbin.com

We’ll discuss currentTarget and the .find() method later in the course