|
|
change the text color of a textarea
If you’ve ever worked with a large amount of textarea elements, you’ve probably gotten tired of looking at the same text colors. Use the style.color attribute to alter this color to any within the millions available. We use a getElementById() method to access the page element that is uniquely identified with the id attribute. An onMouseOver event is used to trigger the change given in the JavaScript function in the HEAD of the document. <html> <head> <script type="text/javascript"> function newColor(color) { document.getElementById('x').style.color=color; } </script> </head> <body> <p> This example demonstrates how to change the text color of a textarea.</p> <p>Mouse over the three colored table cells, and the textarea will change color:</p> <table width="100%"> <tr> <td bgcolor="red" onmouseover="newColor('red')"></td> <td bgcolor="blue" onmouseover="newColor('blue')"></td> <td bgcolor="green" onmouseover="newColor('green')"></td> </tr> </table> <form> <textarea id="x" rows="5" cols="20"></textarea> </form> </body> </html> The coloring method used may be named colors, hex colors or RGB colors. Note that you would use the style.color attribute to change the text color. If you’d like to change the background color as well, simply state a style.background attribute with the style.color attribute given in the JavaScript function within the HEAD of the document. You would usually state the background coloring on the line below to keep the statements readable.
|
|