Индикация части текста в поле ввода

Как можно динамически наложить на input или textarea блок с атрибутом contenteditable? И этот блок не должен внешне отличаться от него. Нужно это для того чтобы стилизовать часть текста вводимого в инпут.

function renderIndicator(elem) {
const indicator = document.createElement('div');
indicator.classList.add('indicator');
indicator.setAttribute('contenteditable', 'true');
indicator.style.cssText = `
    color: green;
    position: absolute;
    top: 0; 
    left: 0;
    z-index: 1;
`;
elem.parentElement.style.position = 'relative';
elem.parentElement.prepend(indicator);

Ответы (0 шт):