

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to convert a node list to an array in JavaScript?
Following is the code to convert a node list to an array in JavaScript −
Example
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .sample { display: inline-block; font-size: 20px; font-weight: 500; color: white; background-color: blue; padding:10px; width: 100px; height: 100px; } </style> </head> <body> <h1>Convert a node list to an array</h1> <div class="sample">1</div> <div class="sample">2</div> <div class="sample">3</div> <div class="sample">4</div> <br> <button class="Btn">CLICK HERE</button> <h3>Click on the above button to change colors of all the above div </h3> <script> let sampEle = document.querySelectorAll('.sample'); let BtnEle = document.querySelector('.Btn'); BtnEle.addEventListener('click',()=>{ Array.from(sampEle).forEach(item=>{ item.style.backgroundColor = 'red'; }) }) </script> </body> </html>
Output
On clicking the ‘CLICK HERE’ button −
- Related Questions & Answers
- How to convert an array to a list in Java?
- How to convert an Array to a List in Java Program?
- How to convert a list into an array in R?
- Java program to convert a list to an array
- Java program to convert an array to a list
- How to convert an array into a complex array JavaScript?
- How to convert a list to array in Java?
- JavaScript Convert an array to JSON
- How to convert an object into an array in JavaScript?
- Can we convert a list to an Array in Java?
- How to convert an array into JavaScript string?
- How to convert a JavaScript array to C# array?
- Convert an Array to a Circular Doubly Linked List in C++
- How to convert nested array pairs to objects in an array in JavaScript ?
- How to convert PHP array to JavaScript array?
Advertisements