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

91
Vistas
simple getElementsByClassName javascript not working in wordpress footer

I have a 1 liner JS in the footer and I can't get getElementsByClassName to work to tweak style attributes. "Hello World" works, so it must be my syntax?

The footer code is this:

<script>
var test = document.getElementsByClassName("elementor-widget-container");
test.style.background-color = 'white';  
var widgets = document.getElementsByClassName("widgets_wrapper");
widgets.style.margin = "0px";
</script>
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

document.getElementsByClassName returns a list of nodes. Even if there's only one.

So what you (probably) want to do is:

var test = document.getElementsByClassName[0]

In the future, try, for instance, to run console.log(test) to see what you're working with, before writing more code to manipulate that variable/element.

about 4 years ago · Juan Pablo Isaza Denunciar

0

getElementsByClassName returns an array like object, even if theres only one. You can try:

var test = document.getElementsByClassName("elementor-widget-container")[0];

or:

test[0].style.background-color = 'white';  
about 4 years ago · Juan Pablo Isaza Denunciar

0

The problem is that test is an array of Node not only Node. So, you will do like this :

<script>
    let tests = document.getElementsByClassName("elementor-widget-container");
    tests.forEach( test => { test.style.background-color = 'white'; } );  
    let widgets = document.getElementsByClassName("widgets_wrapper");
    widgets.forEach( widget => { widget.style.margin = "0px"; } );
</script>
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