0

var option = document.getElementById("o");
option.text = "B";
<option id="o">A</option>

I want to change the text of an option tag with javascript. For this, I use the text property like above but the same result is also applied if I use the innerHTML property. Which one should I choose? Thanks

BNazaruk
  • 6,300
  • 3
  • 19
  • 33
darkchampionz
  • 1,174
  • 5
  • 24
  • 47
  • In this case as you don't need any html to insert `text` should work for you. – Emran Feb 10 '22 at 17:42
  • 1
    I can't see how the linked dup answers the question ..? [The documentation](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option) says: "_Permitted content: Text, possibly with escaped characters (like \é)._", `option` element can't contain HTML, hence it's not useful to set non-standard property, stick to [`text`](https://html.spec.whatwg.org/multipage/form-elements.html#htmloptionelement), it works with all browsers. – Teemu Feb 10 '22 at 17:58

0 Answers0