How to apply multi-colored innertext to <DIV>

  • Thread starter Thread starter JM
  • Start date Start date
J

JM

Hi all,

I have this sample code:

var d=document.getElementById("txt");
d.innerText = d.innerText.toString() + "\n\n" + "<b>"+result+"</b>";

where 'txt' is of type <DIV>, and 'result' is some custom string. I
want to parse the result string and change some of the words to other
color. How do I do this? Is changing colors possible with innerText, or
should I use innerHTML. If so, how do I apply this using innerHTML?


Thanks,

JM
 
Parse the result string and enclose the words <span> tag with the required
color in style attribute. Then assign it to innerHtml property of the div
tag.

Hi all,

I have this sample code:

var d=document.getElementById("txt");
d.innerText = d.innerText.toString() + "\n\n" + "<b>"+result+"</b>";

where 'txt' is of type <DIV>, and 'result' is some custom string. I
want to parse the result string and change some of the words to other
color. How do I do this? Is changing colors possible with innerText, or
should I use innerHTML. If so, how do I apply this using innerHTML?


Thanks,

JM
 
innerText is text only, no markup. you need to use innerHTML.

-- bruce (sqlwork.com)
 
Back
Top