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>
4
Answers
finally got it to work, but had to change strategy:
document.getElementsByClassName
returns a list of nodes.Even if there’s only one.
So what you (probably) want to do is:
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.
getElementsByClassName returns an array like object, even if theres only one. You can try:
or:
The problem is that test is an array of Node not only Node. So, you will do like this :