JSFiddle - React, Tailwind, and code Playground

HTML

<ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>

</ul>

<ul>
    <li>a</li>
    <li>b</li>
</ul>

CSS

ul li {
    background-color: silver;
}

ul li:nth-child(1){
    background-color: cyan;
}

ul li:nth-child(4){
    background-color: red;
}

ul li:nth-of-type(5){
    background-color: yellow;
}

JavaScript

var ul = document.getElementsByTagName('ul');
var li = [];
for(var i=0; i< ul.length; i++) {
    var item = ul[i].querySelectorAll('li');
    for(var j=0; j< item.length; j++) {
    	li.push(item[j]);
    }
    if(li[4]) {
        li[4].style.backgroundColor = "yellow";
        break;
    }
}