tags:

views:

75

answers:

4

Hi!

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?

+3  A: 
divElement.innerHTML = '&lt;';
Darin Dimitrov
+5  A: 

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/

Alex JL
thanks!! how do I got the other symbol? '>'Any link to the special characters?
Woho87
@Woho87 — that one's `>`. It stands for "greater than" :) [Wikipedia has a good list of HTML entities.](http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references)
Matchu
@Woho87 sure, I've added a link to another list of entities. Oops, I didn't see Matchu's link actually!
Alex JL
+1  A: 
  • 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

Paco
+1  A: 

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

gov