The problem is a bit strange, when uploading a site to a host in the console an error occurs

jQuery.Deferred exception: Cannot read property 'getElementsByClassName' of null TypeError: Cannot read property 'getElementsByClassName' of null at window.particlesJS (http://fellpayeer.ru/lib/particles.min.js:9:22397) at HTMLDocument.<anonymous> (http://fellpayeer.ru/js/js.js:1:704) at j (http://fellpayeer.ru/lib/jquery-3.1.0.min.js:2:29568) at k (http://fellpayeer.ru/lib/jquery-3.1.0.min.js:2:29882) undefined jquery-3.1.0.min.js:2 Uncaught TypeError: Cannot read property 'getElementsByClassName' of null 

The problem is that when launching the same site on the local host (Open Server) there are no errors, everything works as it should be! What can be wrong? I read on the Internet that people are helped by replacing the jquery version from 3 to 2, I tried, it did not help. What to do?

  • Actually, instead of a page, the server gives you 500 errors. js nothing to do with it. - Visman

1 answer 1

Perhaps some of your script, depending on jQuery or other external libraries - starts to run before loading these libraries.

On the local machine, all external libraries are stored locally on your PC, and loaded quickly. On the server, the browser download takes a little longer, and at such times your script may work before the libraries load.

It is solved simply - in your scripts, all the code that depends on external libraries is tied to the loading events of these libraries. For example, for CKEditor:

 CKEDITOR.on('instanceReady', function(event) { # Ваш код, использующий загруженный редактор CKEditor }); 

And the code using DOM, bind to a full DOM load:

 $(document).ready(function() { # Ваш код, работающий с DOM }); 

Specifically, in your case, in the js/js.js , you call the particlesJS("particles-js"... method particlesJS("particles-js"... , it is called before the DOM loads, which is why the external script simply does not find the tag to which the script should be applied, and throws an error. Bind the particlesJS call to the DOM load event:

 $(document).ready(function() { particlesJS("particles-js", { # Ваши параметры для particlesJS }); }); 
  • Did you look at the site to the questioner before they wrote this answer? - Visman
  • @Visman, at your suggestion looked. And I realized that I really answered correctly. In the js.js file, particlesJS is called before the DOM loads. Thank you for the tip. I will add the answer. - Vitaly Emelyantsev
  • It did not help both files that are indicated in errors are already wrapped in $ (document) .ready (function () {}), and everything just crashes - Dmitry K.
  • Are you jquery-3.1.0.min.js about the particles.min.js and jquery-3.1.0.min.js ? They report an error, but the cause of the error is not in them, but in your js.js file, try to wrap the call to particlesJS in an event, as indicated at the end of my answer. - Vitaly Emelyantsev
  • @DmitryK., That is, 500 server error, which is now on your site, is this normal? - Visman