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 - <
. 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 = '<';
- 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
精彩评论