admin管理员组

文章数量:1415139

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

本文标签: quotltquot sign not showing in javascriptStack Overflow