removeAttribute Javascript

Asked

Viewed 35 times

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.

  • 2

    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.

  • Yes, the id is in a div in html.

  • then add a line with a Debugger before tagAgua.removeAttribute('hiddne') and check if it is being filled at that time.

  • I added a "console.log()" and it entered.

  • places 'Debugger' and sees if it is null at runtime.

  • Places your HTML tbm for easy analysis

  • I solved it. I was calling the script before the html itself.

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.