Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

349
Views
why querySelectorAll does not work or i can not do it ? What is wrong?

I tried to use querySelector All. I added onclick to button. And I made a function and wanted to change divs background. but i does not work even if i clicked the button. I want to know what i am doing wrong

<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="jquery-3.5.1.min.js"></script>
<link rel="stylesheet" href="stil.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>

    <button type="button" onclick="basla()">TIKLA</button> I ADDED ONCLİCK TO START FUNCTION
    
<div id="kutu1" class="kutu"></div>
<div id="kutu2" class="kutu"></div>
<div id="kutu3" class="kutu"></div>


<script>

function basla () {                          

var kutular = document.querySelectorAll(".kutu");                 

kutular.style.background = "white";      

}



</script>

</body>
</html>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

document.querySelectorAll returns a NodeList. You cannot access .style on the NodeList directly.

var kutular = document.querySelectorAll(".kutu");
kutular.style.background = "white"; // ❌

You must iterate over the resulting NodeList using for..of

var kutular = document.querySelectorAll(".kutu");
for (const elem of kutular) {
  elem.style.background = "white"; // ✅
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!