How to apply multi-colored innertext to <DIV>

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
 
S

Siva M

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
 
B

Bruce Barker

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

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top