Add eventlistener only if element exists – WordPress
I want to add eventlistener to a html element. But It creates js error when the element doesn't exist. The element exists only on some pages. // (A) ATTACH CLICK LISTENER ON PAGE LOAD window.addEventListener("load", () => { document.getElementById("download_mp3j_0").addEventListener("click", doSomething);…