Error: Uncaught TypeError: Cannot read property ‘style’ of undefined. Styles are working when I’m choosing an input.
this input:
var input = document.getElementById('pa_rama').value;
var option = document.getElementById('pa_razmer').value;
let ramka = document.getElementsByClassName('woocommerce-product-gallery__image');
if(input == 'chernaya') {
for(var i=0; i < input.length; i++) {
ramka[i].style.border = '50px solid black';
ramka[i].style.boxShadow = 'none';
}
}
What is wrong?
2
Answers
You should take a look at this post :
How to correctly iterate through getElementsByClassName
What you probably need to do is :
Check whether you added the
<script> js file
in bottom of the htmlor try with
onload
function in javascript