Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

107
Vistas
I want to change this paragraph through javascript
document.querySelector("#myBtn").onclick = function () {
  console.log("Clicked");
  const h1 = document.querySelector("#myH1");
  const underline = document.createElement("u");
  underline.innerText = "Hey bro.";
  h1.innerText = "";
  h1.append(underline);

  const p = document.querySelector(".myP");
  p.forEach((element) => (element.innerText = "Thank You!!!!"));

  const btn = document.querySelector("button");
  btn.remove();
};
p.forEach((element) => (element.innerText = "Thank You!"));

I got: Error TypeError p.forEach is not a function

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

querySelector returns just 1 element. Use querySelectorAll to return a list of elements matching the given selector.

about 4 years ago · Juan Pablo Isaza Denunciar

0

The Document method querySelector() returns the first Element within the document that matches the specified selector.

You could use the getElementsByClassName instead

var p = document.getElementsByClassName('myP"');
for (let i = 0; i < p.length; i++){
  p[i].innerText = "Thank You!!!!";
} 
about 4 years ago · Juan Pablo Isaza Denunciar

0

First , Check you createated a query or not.Then variable p is not defined inside the function.use query selector all for return all the elements in the query.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda