button onclick change background color css code example

Example 1: css onclick change color

<style>
.dabutton:focus {
    background-color:yellow;
}
</style>
<button class="dabutton"></button> // <-- usage

Example 2: change background color on button click in javascript

<style>
  .bg1 {
  	background-color: red;
  }
</style>

<button id="btnChangebgColor" />

<script>
  	$(document).ready(function(){
      $("#btnChangebgColor").click(function() {
        $(this).addClass(".bg1");
      }); 
	}
</script>

Tags:

Html Example