JavaScript&Platform/jQuery2025. 1. 21. 14:07

[jquery] select on change / jquery value/text 가져오기

HTML

<select id="example">
  <option value="1">Option 1</option>
  <option value="2">Option 2</option>
  <option value="3">Option 3</option>
</select>

Jquery

$('#example').on('change', function () {
  const selectedVal = $(this).val();  // 선택된 option 의 value
  console.log('Selected Value:', selectedVal);
  const selectedText = $(this).find('option:selected').text(); // 선택된 option 의 text
  console.log('Selected Text:', selectedText);
});
Posted by 비니미니파파