javascript - InnerHTML with special character is trimming the data - Stack Overflow

InnerHTML with special character is trimming the data.elem.innerHTML = displayedObjects.name;here the d

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
Add a ment  | 

1 Answer 1

Reset to default 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;

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745175994a4615194.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信