"<" sign not showing in javascript? - Stack Overflow

I have a div-element that I want to show the symbol '<'.div-element.innerHMTL = '<

I have a div-element that I want to show the symbol '<'.

div-element.innerHMTL = '<';

The string actually do not appears, I think the problem lies in that the browser thinks that it is a beginning of a tag element

Anyone seen this problem before?

I have a div-element that I want to show the symbol '<'.

div-element.innerHMTL = '<';

The string actually do not appears, I think the problem lies in that the browser thinks that it is a beginning of a tag element

Anyone seen this problem before?

Share Improve this question asked Sep 25, 2010 at 19:53 einsteineinstein 13.9k29 gold badges86 silver badges110 bronze badges 4
  • 1 Have you tried div-element.innerHTML = '&lt;' ? – phimuemue Commented Sep 25, 2010 at 19:54
  • 2 You can also use innerText instead of innerHtml – Nikita Rybak Commented Sep 25, 2010 at 19:56
  • 1 I'm assuming you're not actually using div-element in your Javascript. The hyphen is not a legal variable name character. – eyelidlessness Commented Sep 25, 2010 at 20:02
  • 2 Have you mistyped innerHTML as innerHMTL in your code as well or only in this question? – Luke Woodward Commented Sep 25, 2010 at 20:27
Add a ment  | 

4 Answers 4

Reset to default 5

You should use an HTML entity - &lt;. This will be displayed by the browser as <, rather than being interpreted as the start of an HTML tag.

Here's a handy list of mon HTML entities: http://www.danshort./HTMLentities/

divElement.innerHTML = '&lt;';
  • innerHTML sets does not encode and can be used to set html elements.
  • innerText sets encodes and cannot be used to set html elements.

You should use innerText when you just want to set text or you should encode the text when you want to mix html with text

This might be useful link which shows all symbols http://www.w3schools./HTML/html_entities.asp

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

相关推荐

  • &quot;&lt;&quot; sign not showing in javascript? - Stack Overflow

    I have a div-element that I want to show the symbol '<'.div-element.innerHMTL = '<

    4小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信