Home / Programs / How to select all li at once using JavaScript
🚀 Programming Example

How to select all li at once using JavaScript

👁 184 Views
💻 Practical Program
📘 Step Learning
In this section you will learn that how to select all li or any tag at once using JavaScript

💻 Program Code

<!DOCTYPE html>
<html>
    <body>
        <ul>
            <li> Hello </li>
            <li> Hello </li>
            <li> Hello </li>
            <li> Hello </li>
            <li> Hello rumman </li>
        </ul>
    </body> 
</html>


<!- Script Code -->
<script>
    let elementLi = document.getElementsByTagName('li');
    Array.from(elementLi).forEach(element =>{
        console.log(elementLi);
        element.style.color = 'blue';
        element.style.boxShadow = '2px 5px #888888';
        element.style.border = '1px solid';
        element.style.padding = '10px';
    });
</script>
                        

🖥 Program Output

Copy above code and run it in your environment to see the output. 
                            

📘 Explanation

No
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.