The error message says that getComputedStyle
requires the parameter to be Element
type. You receive it because the parameter has an incorrect type.
The most common case is that you try to pass an element that doesn't exist as an argument:
my_element = document.querySelector(#non_existing_id);
Now that element is null
, this will result in mentioned error:
my_style = window.getComputedStyle(my_element);
If it's not possible to always get element correctly, you can, for example, use the following to end function if querySelector
didn't find any match:
if (my_element === null) return;