Reputation: 985
I tried this:
in constant.js
const CONFIRM_BUTTON = document.querySelector(".confirm-button");
export { CONFIRM_BUTTON };
in some-file.js,
import { CONFIRM_BUTTON } from './constants';
CONFIRM_BUTTON.onclick = someFunction;
I am getting Cannot set property 'onclick' of null
error in doing so.
If in some-file.js file, I do following, it works:
const CONFIRM_BUTTON = document.querySelector(".confirm-button");
CONFIRM_BUTTON.onclick = someFunction;
I am trying to do this const CONFIRM_BUTTON = document.querySelector(".confirm-button");
once and use it multiple js files? How can I do that?
Upvotes: 0
Views: 36