In html, how to count the real characters shown in a innerHTML?
For example, In
elem_output = document.getElementById("example_id");
I don't know which element has
#example_id in your code, but
element.innerText.length should work.
Edit: Other answers suggest the use of
textContent instead of
innerText. I think that depending on OP's real needs one or the other (or even
innerHTML, which appears in question's title) could be suitable. So, I'd suggest to read carefully the differences between those properties in the docs:
Edit 2: OP's question says real characters shown in a innerHTML, so I'd go with
innerTextis aware of style and will not return the text of hidden elements, whereas
var tag = document.getElementById('test'); console.log(tag.innerText.length)