Hello,
I use one JS file for all my scripts (I import many in one file and bundle it with wepback into another file which I use in production).
For example I use something like this:
let submitButton = document.querySelector("input[type='submit']");
and then I add event listener:
submitButton.addEventListener(...);
This works fine in html1
file but I get ReferenceError in html2
file, this is expected because I don’t have input
with type submit
.
Should I do something like this in order to prevent error:
if (submitButton) { submitButton.addEventListener(...); }
?
There is no other choice.
1 Like
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.