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 = '<'
? – 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
asinnerHMTL
in your code as well or only in this question? – Luke Woodward Commented Sep 25, 2010 at 20:27
4 Answers
Reset to default 5You should use an HTML entity - <
. 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 = '<';
- 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
版权声明:本文标题:"<" sign not showing in javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745228630a2648723.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论