"change" event

The change event is fired for <input>, <select>, and <textarea> elements when an alteration to the element's value is committed (entered) by the user. Unlike the input event, the change event is not necessarily fired for each alteration to an element's value.

  • "change" event:value 被確認之後 (如:按 enter) 才會觸發的事件。

  • "input" event:只要 value 發生改變就會觸發的事件。

when "change" event fires

code example

const list = $('.ice-cream');

list.onchange = (e) => {
  const result = $('.result');
  result.textContent = `You like ${e.target.value}`;
};

Last updated