how to change background color of textarea and textbox - javascript

StackOverflow https://stackoverflow.com/questions/23324133

  •  10-07-2023
  •  | 
  •  

سؤال

I'm trying to change the background color of the textarea and text box. All this must be done when the user presses the button click, it activates a function that changes the color of the two components at random. The code I've written does not work, could you help me?

<html>
<body>
<textarea id="text"></textarea><br/>
<input type="text" id="c"><br/>
<input type="button" onclick="as()" value="clicca">
</body>

<script>

function as()
{

var t = document.getElementById('text');
var c = document.getElementById('c');

t.style="color: red; background-color: lightyellow"

}

</script>
</html>
هل كانت مفيدة؟

المحلول

You can change the backgroundColor directly with JavaScript:

t.style.backgroundColor='blue';

نصائح أخرى

 t.css("background-color","red")
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top