Javascript runtime error: Unable to get the indefinite or null reference style property

Asked

Viewed 1,697 times

0

I have this mistake below:

inserir a descrição da imagem aqui

I am trying to avoid this error by using the check below:

$(document).ready(function () {
    if (document.getElementById('panelActivex') != null) {
        document.getElementById('panelActivex').style.display = 'none';
        document.getElementById('visitorImage').className = 'fld';
    }
});

When I compile the code gets like this:

$(document).ready(function () {
        document.getElementById('panelActivex').style.display = 'none';
        document.getElementById('visitorImage').className = 'fld';   
});

And it’s giving the print error. How do I fix it?

  • Why are you doing document.getEl... if you’re using jQuery? $('#panelActivex').css('display', 'none') is much simpler and probably solves this problem

  • The element panelActivex exists or not on the page?

  • Opa. I’m going to test. Sorry but I’m not good at Javascript.

  • I’ll check @Sam but I think there is.

  • @Sam. It’s giving the same error. I’ve already cleared the cache and even restarted the machine. I put the function just like the one you posted but when I compile and arrive at the error search and the code displayed in VS2015 is the old one, as if I didn’t change anything. You know what could be causing this?

  • This code change problem was Cache. Solved.

Show 1 more comment

1 answer

1


Use the method .hide() jQuery (since you are using $.ready) for the element panelActivex and in the element visitorImage you change class also with jQuery:

$(document).ready(function () {
  $('#panelActivex').hide();
  $('#visitorImage').attr('class', 'fld');
});

This avoids the cited error because even if the element does not exist, jQuery does not return the null or undefined reference error.

Browser other questions tagged

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