Skip to content

Instantly share code, notes, and snippets.

@Maighdlyn
Created February 24, 2017 02:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Maighdlyn/7a1fc9afc390528e4c1e410cfe7ca202 to your computer and use it in GitHub Desktop.
Save Maighdlyn/7a1fc9afc390528e4c1e410cfe7ca202 to your computer and use it in GitHub Desktop.
Color Picker
<body>
<h1>Color Picker</h1>
<h3>Background Color Selector</h3>
<p>To select a background color, please click on your prefered color below:</p>
<div>
<button class="red"></button>
<button class="orange"></button>
<button class="yellow"></button>
<button class="green"></button>
<button class="blue"></button>
<button class="purple"></button>
<button class="grey"></button>
<button class="white"></button>
</div>
</body>
$(document).ready(function() {
$('button').addClass('buttonClass');
$('button').click(function() {
$('body').removeClass();
var color = $(this).attr('class');
$('body').addClass(color);
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
.buttonClass {
border-radius: 20px;
padding: 20px;
margin: 5px;
}
.red {
background-color: FireBrick;
}
.orange {
background-color: orange;
}
.yellow {
background-color: yellow;
}
.green {
background-color: green;
}
.blue {
background-color: DeepSkyBlue;
}
.purple {
background-color: RebeccaPurple;
}
.grey {
background-color: grey;
}
.white {
background-color: white;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment