I am trying to write a function that prints a certain text into a <div id="1">
tag.
The string should mark certain index values in different color.
What I have written now is to go to all the index values I have and add a <font color="color">
tag, and then I add it using div1.innerHTML = result;
Its a lot of work, and its very complicated. Is there another way that I can create a string object like I've described without these HTML tags?
If I can do that then I would just use div1.appendChild(String);
You can change the color of text in your Word document. Select the text that you want to change. On the Home tab, in the Font group, choose the arrow next to Font Color, and then select a color. You can also use the formatting options on the Mini toolbar to quickly format text.
To change color in JavaScript, do this: element. style. color = 'red' .
To change some of the text in the HTML document to another color use the FONT COLOR Tag. To change the color of the font to red add the following attribute to the code to the <FONT COLOR=" "> tag. #ff0000 is the color code for red.
To set the font color in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <p> tag, with the CSS property color. HTML5 do not support the <font> tag, so the CSS style is used to add font color.
I generally am loathe to recommend that anybody use a library that they don't already claim to use, but this is one of those times where the question almost directly asks for a library as an answer :-)
Check out Lettering.JS. It was designed to do exactly what you describe. It wraps your text content by letter or by word or by line (I think) in <span>
tags, under your control. You then use CSS to style elements, or some more JavaScript to manipulate and style the elements it creates for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With