. The string should mark specif...">

Create colorful text in JavaScript

I am trying to write a function that prints specific text into a <div id="1"> .

The string should mark specific index values ​​in different colors.

Now I wrote all the index values ​​that I have, and add the <font color="color"> , and then add it using div1.innerHTML = result;

Its a lot of work and its very difficult. Is there any other way to create a string? an object, as I described without these HTML tags?

If I can do this, I just use div1.appendChild(String);

+6
source share
2 answers

I'm generally sorry to recommend that someone use a library that they have not yet stated, but this is one of those cases where the question almost directly requests the library as an answer :-)

Check out Lettering.JS . It was designed to do what you describe. It wraps your text content with a letter or word or line (I think) in the <span> tags you control. Then you use CSS to style the elements or some more JavaScript to control and style the elements that it creates for you.

+6
source

if you are looking for syntax coloring, you can try this jQuery plugin. http://www.steamdev.com/snippet/

0
source

Source: https://habr.com/ru/post/889462/


All Articles