gpt-4o-mini-2024-07-18· OpenAI
WildChat-4.8M (AI2)
how do i change text color on a button in javascript
- User
how do i change text color on a button in javascript
- Assistant
To change the text color of a button using JavaScript, you can access the button element and modify its CSS properties. Here are a few different ways to do it:
Method 1: Inline Style
You can use the
styleproperty to set the text color directly:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Change Button Text Color</title> </head> <body> <button id="myButton">Click Me!</button> <script> const button = document.getElementById('myButton'); button.style.color = 'red'; // Change text color to red </script> </body> </html>