0

To simply things, I have a class:

class Show {
    heading;
    another;

    constructor() {
        this.heading = document.querySelector('.foo');
        this.another = document.querySelector('.bar');
    {

    render(name, text) {
      this.name.textContent = text;
    }
}

I want to receive the name of the HTML element to edit from another class and set the text. This is so I can use OOP and modules. I keep getting error messages in the console saying "this.name" is not set. If I wrap everything in back-ticks:

`this.${name}.textContent = ${text}`

it also doesn't work. It seems to evaluate to a string and doesn't recognise 'this'. ( I have looked at how to remove wrapping quotation marks to no avail. Is what I want to do possible in Javascript? Thanks.

Fari
  • 19
  • 4

0 Answers0