Change input button color and background color with onClick event in JavaScript
Description
The following code shows how to change input button color and background color with onClick event.
Example
<!-- w ww .j ava 2 s. co m-->
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<Form name="aForm">
<Input type="Button"
name="Big_Button"
value="Big Button"
onClick="onClickHandler(this)";>
</Form>
<script type="text/javascript">
function onClickHandler(elem) {
elem.style.background = 'white';
elem.style.color = 'black';
}
</script>
</body>
</html>
The code above generates the following result.
Javascript Tutorial Button
Access form button with its name through do...
Access form with form name through document...
Add click action to a Button in JavaScript
Add click event handler for input button in...
Add click event handler to input onClick ev...
List properties from a form button in JavaS...
Return false in form button click event to ...
Use Image as the submit button in JavaScrip...
Access form button with its name through do...
Access form with form name through document...
Add click action to a Button in JavaScript
Add click event handler for input button in...
Add click event handler to input onClick ev...
Change input button color and background co...
Get current value of the submit button whic...List properties from a form button in JavaS...
Return false in form button click event to ...
Use Image as the submit button in JavaScrip...