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

90
Views
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 answers
Answer question

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 Report

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 Report

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 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!