Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js Changing selected option by option text

const changeSelected = (e) => {
  const text = 'Steve Jobs';
  const $select = document.querySelector('#mySelect');
  const $options = Array.from($select.options);
  const optionToSelect = $options.find(item => item.text ===text);
  optionToSelect.selected = true;
};
Source by alvarotrigo.com #
 
PREVIOUS NEXT
Tagged: #js #Changing #selected #option #option #text
ADD COMMENT
Topic
Name
9+9 =