InnerHTML with special character is trimming the data.
elem.innerHTML = displayedObjects.name;
here the displayedObjects.name
contains a string like Test&string
. The above statement is assigning the value only Test
,
What could be done here?
InnerHTML with special character is trimming the data.
elem.innerHTML = displayedObjects.name;
here the displayedObjects.name
contains a string like Test&string
. The above statement is assigning the value only Test
,
What could be done here?
Share Improve this question edited Dec 16, 2013 at 15:52 p.s.w.g 149k31 gold badges305 silver badges337 bronze badges asked Dec 16, 2013 at 6:13 user3106224user3106224 112 silver badges3 bronze badges 1- 2 Hm, somebody already edited this, Why you return to plain text again? – vp_arth Commented Dec 16, 2013 at 6:16
1 Answer
Reset to default 7That's because Test&string
isn't actually valid HTML, because &
is an escape character for an HTML entity. If it were properly encoded, it would be Test&string
instead.
If you're just trying to set the text of an element, I'd suggest you use innerText
instead:
elem.innerText = displayedObjects.name;