How do I add styles to elements that are dynamically added by js?

clipboard.png
as shown in the figure, the elements in the red rectangle are rendered dynamically, so how to add text size, color, layout and other styles dynamically? Do you want to write the style and add the class name first, or how to do it?
the layout drawn up by myself is as follows:

        <div class="box">
            <ul>
                <li></li>
                <li></li>
            </ul>
            <ul>
                <li></li>
                <li></li>
            </ul>
        </div>
Apr.15,2021

write the corresponding css, first and then append these class names


 <div class="box">
    <ul>
        <li></li>
        <li></li>
    </ul>
    <ul>
        <li></li>
        <li></li>
    </ul>
</div>

for example, class='box' generally adds all style classes directly. If you really need to modify them in js later, select the corresponding node through the selector to modify it. The difference between static adding nodes and dynamically adding nodes is to render once or multiple times, and dynamically try to mount them to the nodes of the page at one time as far as possible.


this kind of style does not need to be added dynamically with js. Just define the style in advance and add the class

you have defined to the appended string.
Menu