-1

I have this text:

var text = "some instructions";

I want to set to the text some style and then I want to put it to DOM. So I have tried this:

var text = '"<font size="6">This is some text!</font>"';

But I am not getting the desired result. The text is not changed and I getting html tags being displayed as text.

Any idea on how to add html to the text and then add it to the DOM?

Luke P. Issac
  • 1,471
  • 15
  • 32
Michael
  • 13,950
  • 57
  • 145
  • 288

2 Answers2

1

Use innerHTML on the element where you want to add the html

var text = "<div style='color:red;'>abc</div>";
document.getElementById("abc").innerHTML = text;
Nandita Sharma
  • 13,287
  • 2
  • 22
  • 35
0

You can Use this to create a DOM Element with text .

var texttag= document.createElement('text');//create DOM 
var text= document.createTextNode("Please Select Program Course"); //Create Your Text 
texttag.setAttribute("for", "Please Select Program Course"); //Create DOM Attributes
texttag.appendChild(text); //append the text into DOM

that is it ..

imdisney
  • 109
  • 1
  • 13