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

357
Views
¿Por qué querySelectorAll no funciona o no puedo hacerlo? ¿Qué está mal?

Intenté usar querySelector All. Agregué onclick al botón. E hice una función y quería cambiar el fondo de divs. pero no funciona incluso si hice clic en el botón. quiero saber que estoy haciendo mal

 <!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 devuelve una lista de NodeList . No puede acceder a .style en NodeList directamente.

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

Debe iterar sobre la lista de nodos resultante usando 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!