Juan Juan - 4 months ago 12
HTML Question

Setting Value of Output Element via JavaScript in Edge and IE

I have an

output
tag whose value is set dynamically via JavaScript. This works just fine in Chrome and Firefox, but Microsoft browsers (IE and Edge) don't seem to recognize it, and the
value
is always empty for these tags.

HTML:



document.getElementById("owned").value = "Test 1";
document.getElementById("used").value = "Test 2";

<output class="output" id="owned"></output>
<output class="output" id="used"></output>





It even works when I run the code snippet on Stack Overflow.

Question: Is there any reason why the values aren't being set on these browsers? Is there a file that I must import into my HTML for it to work on IE/Edge?

Answer

Use span and .innerHTML. <output> HTML tag seems to not work on Edge.