0
Hello, I have a problem, I need to add a color to a text that is added inside a textarea through a button.
I tried to use x.style.color="red'"... but it didn’t work, if someone has a solution please introduce me.
Follows the code:
<body>
<textarea name="texto" id="texto">
</textarea>
<button class="button button2" type="button1">Texto</button>
<script>
var textarea = document.querySelector('textarea');
var button1 = document.querySelector('button');
var assinatura1 = 'TEXTO COLORIDO'
button1.addEventListener('click', function() {
textarea.value += assinatura1;
});
</script>
</body>
What would be
x
inx.style.color="red'"
?– Sam
"X" would be the variable, since the text (COLORED TEXT) is passed to the textarea via the signing variable1.
– user65739
You want to change only the text "COLORFUL TEXT" and leave others without coloring?
– Sam
Yes, if possible, since the text "COLORED TEXT" is inserted in the textarea without deleting what was already written.
– user65739
I get it, but there’s already question addressing it. Take a look.
– Sam