"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

ๅ…ƒไปถ

type

event

<input>

radio, checkbox

click

<input>

date, file

select

<select>

select

<input>

text

element loses focus after its value was changed, but not committed

<textarea>

(same above)

code example

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

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

Last updated