I need to make it so that in real time, when I type words or letters, they turn green in textarea. But at the same time, mathematical signs or numbers did not change color.
My HTML code:
<textarea id="input" class="syncscroll" oninput="updateCode()" rows="10" placeholder="Enter an expression to start"></textarea>
I’ve tried like this:
function highlightNumbers() {
const input = document.getElementById('input')
const htmlContent = input.innerHTML
// Заменяем числа в тексте на версии с установленным цветом
const formattedContent = htmlContent.replace(
/(d+(.d+)?)/g,
'<span class="number">$1</span>'
)
input.innerHTML = formattedContent
}
highlightNumbers()
style.css:
.number {
color: green;
}
New contributor
Nikita Gostevsky is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.