0
I am learning Javascript and have made the following function:
var marcaAgua = document.getElementById('marca-agua');
var reso = window.matchMedia("(min-width: 768px)");
function pngReso(reso){
if (reso.matches){
marcaAgua.removeAttribute("hidden");
window.onscroll = function() {navbarFunc()};
} else {
console.log('entoru mobile');
window.onscroll = null;
}
}
pngReso(reso);
reso.addListener(pngReso);
However, in the browser keeps giving the error:
Cannot read Property 'removeAttribute' of null at pngReso
And the function isn’t executed, and I don’t know what I’m doing wrong.
Does that watermark of yours exist in the gift? Check that the rangeName variable is being filled in, I think it’s coming to your function as null value.
– Maycon F. Castro
Yes, the id is in a div in html.
– Sumback
then add a line with a Debugger before tagAgua.removeAttribute('hiddne') and check if it is being filled at that time.
– Maycon F. Castro
I added a "console.log()" and it entered.
– Sumback
places 'Debugger' and sees if it is null at runtime.
– Maycon F. Castro
Places your HTML tbm for easy analysis
– Diego Marques
I solved it. I was calling the script before the html itself.
– Sumback