Is there a way to change the color of a button, or at least the color of the button label programmatically? I can change the label itself with
document.getElementById("button").object.textElement.innerText = "newlabel";
But how to change the color?
</head> <body> <input type="button" onmouseover="ChangeColor()" value="Button" id="btn1" />
All style elements in your HTML button tag should be placed within quotation marks. Type background-color: in the quotation marks after "style=". This element is used to change the background color of the button. Type a color name or hexadecimal code after "background-color:".
Use the setBackground method to set the background and setForeground to change the colour of your text.
To set Android Button background color, we can assign android:backgroundTint XML attribute for Button in layout file with the required Color Value. To programmatically set or change Android Button background color, we may call pass the method Button.
I have finally found a working code - try this:
document.getElementById("button").style.background='#000000';
Here is an example using HTML:
<input type="button" value="click me" onclick="this.style.color='#000000'; this.style.backgroundColor = '#ffffff'" />
And here is an example using JavaScript:
document.getElementById("button").bgcolor="#Insert Color Here";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With