Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript:output symbols and special characters

Tags:

People also ask

How do you escape a special character in JavaScript?

To use a special character as a regular one, prepend it with a backslash: \. . That's also called “escaping a character”.

How do you check if a character is a special character in JavaScript?

To check if a string contains special characters, call the test() method on a regular expression that matches any special character. The test method will return true if the string contains at least 1 special character and false otherwise.


I am trying to include some symbols into a div using JavaScript.
It should look like this:

x ∈ ℝ

, but all I get is: x ∈ ℝ.

var div=document.getElementById("text");
var textnode = document.createTextNode("x ∈ ℝ");					
div.appendChild(textnode); 
<div id="text"></div>

I had tried document.getElementById("something").innerHTML="x &#8712; &reals;" and it worked, so I have no clue why createTextNode method did not.

What should I do in order to output the right thing?