Button and Multi Select
Change class name on click in jQuery
by Leonardo Trimarchi
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.5.1/chosen.jquery.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.5.1/chosen.min.css">
<div class="wrap">
<!-- Begin Multiple Dropdown -->
<form class="form" id="foo_form">
<label for="foo_select" class="screen-reader-text">Click to select an skill set</label>
<select id="foo_select" class="dropdown" form="foo_form" multiple data-placeholder="Click to select an option...">
<option value="Paint">Paint</option>
<option value="Clean">Clean</option>
<option value="Carpet">Carpet</option>
<option value="Resurface">Resurface</option>
<option value="Maintenance">Maintenance</option>
</select>
</form>
<!-- End Multiple Dropdown -->
<button id = "btnSubmit" class="btn third">Button 3</button>
</div><!-- .wrap -->
CSS
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
background: #2c3e50;
font-family: 'Montserrat', sans-serif;
font-size: 16px;
}
body {
display: -webkit-box;
display: flex;
flex-wrap: wrap;
justify-content: space-around;
-webkit-box-align: center;
align-items: center;
align-content: center;
}
h1 {
color: #f1c40f;
font-size: 4rem;
text-transform: uppercase;
display: block;
width: 100%;
text-align: center;
}
@media screen and (max-width: 600px) {
h1 {
font-size: 3rem;
}
}
p {
color: #f1c40f;
font-size: 1.2rem;
width: 100%;
padding: 20px;
text-align: center;
}
.btn {
box-sizing: border-box;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
background-color: transparent;
border: 2px solid #e74c3c;
border-radius: 0.6em;
color: #e74c3c;
cursor: pointer;
display: -webkit-box;
display: flex;
align-self: center;
font-size: 1rem;
font-weight: 400;
line-height: 1;
margin: 20px;
padding: 1.2em 2.8em;
text-decoration: none;
text-align: center;
text-transform: uppercase;
font-family: 'Montserrat', sans-serif;
font-weight: 700;
}
.btn:hover, .btn:focus {
color: #fff;
outline: 0;
}
.first {
-webkit-transition: box-shadow 300ms ease-in-out, color 300ms ease-in-out;
transition: box-shadow 300ms ease-in-out, color 300ms ease-in-out;
}
.first:hover {
box-shadow: 0 0 40px 40px #e74c3c inset;
}
.second {
border-radius: 3em;
border-color: #1abc9c;
color: #fff;
background-image: -webkit-gradient(linear, left top, right top, from(rgba(26, 188, 156, 0.6)), color-stop(5%, rgba(26, 188, 156, 0.6)), color-stop(5%, #1abc9c), color-stop(10%, #1abc9c), color-stop(10%, rgba(26, 188, 156, 0.6)), color-stop(15%, rgba(26, 188, 156, 0.6)), color-stop(15%, #1abc9c), color-stop(20%, #1abc9c), color-stop(20%, rgba(26, 188, 156, 0.6)), color-stop(25%, rgba(26, 188, 156, 0.6)), color-stop(25%, #1abc9c), color-stop(30%, #1abc9c),...
JavaScript
/**
* Chosen: Multiple Dropdown
*/
window.WDS_Chosen_Multiple_Dropdown = {};
( function( window, $, that ) {
// Constructor.
that.init = function() {
that.cache();
if ( that.meetsRequirements ) {
that.bindEvents();
}
};
// Cache all the things.
that.cache = function() {
that.$c = {
window: $(window),
theDropdown: $( '.dropdown' ),
};
};
// Combine all events.
that.bindEvents = function() {
that.$c.window.on( 'load', that.applyChosen );
};
// Do we meet the requirements?
that.meetsRequirements = function() {
return that.$c.theDropdown.length;
};
// Apply the Chosen.js library to a dropdown.
// https://harvesthq.github.io/chosen/options.html
that.applyChosen = function() {
that.$c.theDropdown.chosen({
inherit_select_classes: true,
width: '300px',
});
};
// Engage!
$( that.init );
})( window, jQuery, window.WDS_Chosen_Multiple_Dropdown );
$(document).ready(function() {
$("#btnSubmit").click(function(){
var data = $('#foo_select').val();
alert(data);
});
});