![]() |
Sometimes, on a web page, when a user clicks a button it gets difficult to understand whether the button is clicked or not. In such cases, you can change the background color of the button to indicate that the button is clicked. The below methods can be used to change background color of a button on click. Table of Content Using :active pseudo selectorWe can change the color of a button when we click on it using the :active pseudo property of CSS. This property changes the color of the button when we click on the button. Syntax:selectedHTMLElement:active{ Example: The below code will explain the use of the :active pseudo property to change the color of a button on click.
Output: Using JavaScriptYou can also use the addEventListener() method of JavaScript to add click event and change the color of the button to a particular button permanently. Syntax: selectedHTMLElement.addEventListener('click', callbackFn); Example: The below code will explain the use of JavaScript to change the color of a button on click.
Output: |
Reffered: https://www.geeksforgeeks.org
HTML |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 16 |