einstein
einstein

Reputation: 13850

"<" 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 the browser thinks that it is a beginning of a tag element

Anyone seen this problem before?

Upvotes: 3

Views: 760

Answers (4)

JAL
JAL

Reputation: 21563

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/

Upvotes: 5

kobe
kobe

Reputation: 15835

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

Upvotes: 1

Darin Dimitrov
Darin Dimitrov

Reputation: 1039120

divElement.innerHTML = '&lt;';

Upvotes: 4

Paco
Paco

Reputation: 8381

  • 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

Upvotes: 1

Related Questions