Sunday, 7 August 2022

Change Content and color using querySelectorAll()

 index.html

<!DOCTYPE html>
<html lang="en">
<body>
<ul class="uls">
    <li class="lis">home</li>
    <li class="lis">services</li>
    <li class="lis">contact us</li>
    <li class="lis">about us</li>
</ul>  
<script>
const items=document.querySelectorAll('li:nth-child(odd)');
items.forEach(function(item){
item.innerHTML='i am in red color';
item.style.color='red';
});
</script>
</body>
</html>





No comments:

Post a Comment

Regular Expressions In JS

 index.html file <! DOCTYPE html > < html lang = "en" > < body > < script > let re ; re = /hello/ i ;  ...