1

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?

p.s.w.g
  • 146,324
  • 30
  • 291
  • 331
user3106224
  • 11
  • 2
  • 3

1 Answers1

7

That'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;
p.s.w.g
  • 146,324
  • 30
  • 291
  • 331