03-19-2018 12:14
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

03-19-2018 12:14
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
import document from "document"; var myRect = document.getElementById("myRect"); myRect.onclick = function(e) { console.log("click"); }
The above code works in index.js. What import or other statement do I need to have in index.js for it work if I want to move the code to another file?
Answered! Go to the Best Answer.

Accepted Solutions
03-19-2018 22:32
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


03-19-2018 22:32
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
If you want to put that in a separate file, then you need to import that other file back into index.js.
// index.js import * as blah from "./blah";
blah.initialize();
// blah.js
import document from "document";
export function initialize() {
var myRect = document.getElementById("myRect");
myRect.onclick = function(e) {
console.log("click");
}
}
03-19-2018 22:32
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


03-19-2018 22:32
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
If you want to put that in a separate file, then you need to import that other file back into index.js.
// index.js import * as blah from "./blah";
blah.initialize();
// blah.js
import document from "document";
export function initialize() {
var myRect = document.getElementById("myRect");
myRect.onclick = function(e) {
console.log("click");
}
}
