@VladMokrousov

Как обратиться к значению объекта через cssText?

Есть задача.
5db85750d62e6792499354.jpeg

Никак не могу получить нужные значения через cssText:

let input = document.querySelector('input');
class Options{
  constructor(height, width, bg, fontSize, textAlign){
    this.height = height;
    this.width = width;
    this.bg = bg;
    this.fontSize = fontSize;
    this.textAlign = textAlign;
  }
    createDiv() {
      let div = document.createElement('div');
      document.body.appendChild(div);
      div.textContent = input.value;
      /* Рабочий, но громоздкий код
      div.style.height = this.height;
      div.style.width = this.width;
      div.style.backgroundColor = this.bg;
      div.style.fontSize = this.fontSize;
      div.style.textAlign = this.textAlign;*/
      div.style.cssText=`height: this.height;
      width: 20px;
      `;  
    } 
}
const newDiv = new Options('40px', '42px', 'red', '34px', 'left');
newDiv.createDiv();
  • Вопрос задан
  • 41 просмотр
Решения вопроса 1
@bogomazov_vadim
Вероятно проблема здесь:
div.style.cssText=`height: this.height;
width: 20px;
`;


div.style.cssText=`height: ${this.height}; width: 20px;`
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы