0

i have been walking through this problem of script.js:31 Uncaught TypeError: Cannot read properties of null (reading 'addEventListener') how can i solve this ?

`

masterPlay.addEventListener('click', ()=>{
    if(audioElement.paused || audioElement.currentTime<=0){
        audioElement.play();
        masterPlay.classList.remove('fa-play-circle');
        masterPlay.classList.add('fa-pause-circle');
        gif.style.opacity = 1;
    }
    else{
        audioElement.pause();
        masterPlay.classList.remove('fa-pause-circle');
        masterPlay.classList.add('fa-play-circle');
        gif.style.opacity = 0;
    }
})

I don't know how to solve it ca any body help me out?

  • Moving ` after

    ` tag might solve issue. script loading before body so event is `null`

    – Dreamy Player Nov 20 '22 at 12:32
  • or check if masterPlay is not null then run code `if(masterPlay) {...code}` – Dreamy Player Nov 20 '22 at 12:34
  • Is your ` – Sebastian Simon Nov 20 '22 at 12:40
  • The current best practice is to include your JavaScript code as a [module](//developer.mozilla.org/en/docs/Web/JavaScript/Guide/Modules) using `` which solves this problem and many more. – Sebastian Simon Nov 20 '22 at 12:50

1 Answers1

0

its means masterPlay property is null! you shoud check masterPlay. your informations is not enough

faezeh
  • 113
  • 2
  • 15