Javascript error: Cannot read property 'parentNode' of null

前端 未结 2 1870
广开言路
广开言路 2021-02-19 07:27

The javascript I am using:

javascript: c = \'{unit}, ({coords}) {player} |{distance}| {return}\';
p = [\'Scout\', \'LC\', \'HC\', \'Axe\', \'Sword\', \'Ram\', \         


        
2条回答
  •  轮回少年
    2021-02-19 08:07

    In my case it was a conflict between slider and form validator as they were located on different pages but javascript file would of target both of them simultaneously, so all pages that had no slider would come up with "Cannot read property 'parentNode' of null" error, so I have added to the slider If statement:

    if(document.getElementById("mainImage")){
    var myImage = document.getElementById("mainImage");
    var linkElement = myImage.parentNode;
    

    that solved my problem, try it

提交回复
热议问题