I want to change the BOOK link to red color. how can I change it by JavaScript without adding an id or class? I tried using sections but it's not working. Thanks.
var sections = document.getElementsByClassName('section'); sections.getElementsByTagName("a")[2].style.color="red"; sections.getElementsByTagName("li")[2].style.color="red"; <section> <ul> <li><a href="">1</a></li> </ul> </section> <section> <ul> <li><a href="">2</a></li> </ul> </section> <section> <ul> <li><a href="">3</a></li> </ul> </section> <section> <div class="Search-view"> <ul> <li><a href="">Search</a></li> <li><a href="">View </a></li> <!-- change book to red --> <li><a href="">Book</a></li> <li><a href="">Sell</a></li> <li><a href="">Get</a></li> </ul> </div> </section>
sectionsis an HTML collectionsection .Search-view ul li:nth-child(2) a { color: red; };