A
A
Antonio092020-04-19 01:15:14
JavaScript
Antonio09, 2020-04-19 01:15:14

How to put an exclamation point in the selected option in the select?

not selected. for example - minus
https://jsfiddle.net/gfoyL2dj/

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hzzzzl, 2020-04-19
@Antonio09


document.querySelectorAll('#select option').forEach(n =>
  if (n.selected == true) {
    n.textContent += n.value + '!';
  } else {
    n.textContent += n.value + '-';
  }
)

^
the biggest mistake was that everything after the arrow had to be wrapped in { }, because this is the text of the function, and it should be in brackets

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question