Button Color Change When Selected
I have 10 buttons in one HTML page. I want to use JavaScript to change particular button (button 1) color when button is selected. When user click another button (button 2) the col
Solution 1:
You can define a different CSS class for selected button.
.button-selected {
border: 2px solid red;
}
Then when a button is clicked, you can call the function like this:
functionfocusMe(button) {
document.getElementsByClassName("button-selected")[0].className = "";
button.className = "button-selected";
}
Add this to HTML
<buttonname="button1"onClick="focusMe(this);" />
Post a Comment for "Button Color Change When Selected"