开发者

"<" sign not showing in javascript?

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 t开发者_开发知识库he browser thinks that it is a beginning of a tag element

Anyone seen this problem before?


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 common HTML entities: http://www.danshort.com/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.com/HTML/html_entities.asp

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜