Add color to text in javascript [duplicate]

0

Hello, I have a problem, I need to add a color to a text that is added inside a textarea with a button.

I've tried using x.style.color="red" "... But it did not work, if anyone has a solution please introduce me.

Follow 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>
    
asked by anonymous 18.07.2018 / 20:40

1 answer

0

Hello from javascript you can do it this way:

// Change background color:

document.getElementById('texto').style.backgroundColor = 'blue'; // ou a cor que quiser

// Muda a cor do texto:
document.getElementById('texto').style.color = 'black';
    
18.07.2018 / 20:45