0

when im trying to use the document.getElementById("") command, inside a class method/constructor im receiving error:


Uncaught ReferenceError ReferenceError: document is not defined
    at get element (d:\my Folders\Documents\Code\Tic-tac-toe\scripts\classes.js:13:9)
    at <anonymous> (d:\my Folders\Documents\Code\Tic-tac-toe\scripts\classes.js:129:17)
    at Module._compile (internal/modules/cjs/loader:1105:14)
    at Module._extensions..js (internal/modules/cjs/loader:1159:10)
    at Module.load (internal/modules/cjs/loader:981:32)
    at Module._load (internal/modules/cjs/loader:827:12)
    at executeUserEntryPoint (internal/modules/run_main:77:12)
    at <anonymous> (internal/main/run_main_module:17:47)

*the script is loaded in my html file just like all the scripts that works well, all but this one.

iv'e tried this :

class Button {
    constructor(id) {
        this._id = id;
    }

    get element() {
        return document.getElementById(this._id);
    }
}

const button3 = new Button('actionButton3');

console.log(button3.element);

and tried also this:

class Button {
    constructor(id) {
        this._id = id;
        this._element = document.getElementById(this._id);
    }

    get element() {
        return this._element;
    }
}

const button3 = new Button('actionButton3');

console.log(button3.element);

0 Answers0