Я выделяю текст и к этому выделенному тексту нужно добавить класс.
Ошибка:
Cannot read property 'toggle' of undefined
script.js:
const sendBtn = document.querySelector('.sendBtn'),
close = document.querySelector('.close'),
message = document.querySelector('textarea'),
blockSettingsFontStrong = document.querySelector('.block-settings-font-strong'),
blockSettingsFontItalic = document.querySelector('.block-settings-font-italic'),
blockSettingsFontLine = document.querySelector('.block-settings-font-line'),
leftText = document.querySelector('.left-text'),
centerText = document.querySelector('.center-text'),
rightText = document.querySelector('.right-text'),
clearMessage = document.querySelector('.clear-message'),
blockFonts = document.querySelector('.block-fonts'),
blockFontsFonts = document.querySelector('.block-fonts-fonts'),
arial = document.querySelector('.arial'),
roboto = document.querySelector('.roboto'),
rubik = document.querySelector('.rubik'),
toInput = document.querySelector('.toInput'),
subjectInput = document.querySelector('.subjectInput');
clearMessage.addEventListener('click', () => {
message.value = '';
toInput.value = '';
subjectInput.value = '';
});
blockFonts.addEventListener('click', () => blockFontsFonts.classList.toggle('block-hidden'));
message.addEventListener('select', event => {
const selection = event.target.value.substring(event.target.selectionStart, event.target.selectionEnd);
blockSettingsFontStrong.addEventListener('click', () => selection.classList.toggle('strong'));
blockSettingsFontItalic.addEventListener('click', () => selection.classList.toggle('italic'));
blockSettingsFontLine.addEventListener('click', () => selection.classList.toggle('line'));
leftText.addEventListener('click', () => selection.classList.toggle('left-text'));
centerText.addEventListener('click', () => selection.classList.toggle('center-text'));
rightText.addEventListener('click', () => selection.classList.toggle('right-text'));
arial.addEventListener('click', () => selection.classList.toggle('arial'));
roboto.addEventListener('click', () => selection.classList.toggle('roboto'));
rubik.addEventListener('click', () => selection.classList.toggle('rubik'));
});