O
O
Oksality2020-06-26 00:34:31
JavaScript
Oksality, 2020-06-26 00:34:31

Change style of arbitrary list items?

Hello, I need help in resolving my situation. There is a list that is generated by the plugin, but you need to refer to an arbitrary element of this list.
list structure :

<ul id="test">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>

How can we assign red color to item "3"?
I will clarify that I am looking for this solution for a site on wordpress.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2020-06-26
@Oksality

css don't care if you have wordpress or not. Read this . If the question remains, then come back.
#UPD: Here's how you can:

<ul id="test">
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
</ul>

.red {
    color: red;
}

const hours = new Date().getHours();

if (hours >= 9 && hours <= 15) {
    document.querySelector('#test li:nth-child(3n)').classList.add('red')
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question