Hi, I'm really basic in my JS knowledge, but I usually get by with some research here and there, but I just can't figure this out, and I know it's a really simple issue, I just can't find a solution online anywhere. I've tried a load of different permutations, calling functions, etc. I'm just getting more and more in the weeds. Here's the issue:
I need to add a background to an element that I don't have direct control over. So, I am adding a child DIV into that element and using the following code snippet in a SCRIPT tag in the head of my template to add a class to the grand-parent element:
For some reason, the browser console just keeps throwing "Uncaught TypeError: greyback.closest is not a function" as if it doesn't recognise that closest() isn't a function. I know it's all just down to how I structure this basic script, but I just don't know enough about what I'm doing to get it to work.
Thanks in advance for your help!!!
I need to add a background to an element that I don't have direct control over. So, I am adding a child DIV into that element and using the following code snippet in a SCRIPT tag in the head of my template to add a class to the grand-parent element:
JavaScript:
<script type="text/javascript">
const greyback = document.getElementsByClassName('shaddowChild');
greyback.closest('td').classList.add('backShaddow');
</script>
For some reason, the browser console just keeps throwing "Uncaught TypeError: greyback.closest is not a function" as if it doesn't recognise that closest() isn't a function. I know it's all just down to how I structure this basic script, but I just don't know enough about what I'm doing to get it to work.
Thanks in advance for your help!!!