jQuery addClass example
Change class name on click in jQuery
by zzhsu20
HTML
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<div id="checkbox_block">
<h2>Checkbox nested in label</h2>
<!-- <fieldset> -->
<legend>Bed Type: </legend>
<label for='checkbox-nested-1'>2 Double
<input type='checkbox' name='checkbox-nested-1' id='checkbox-nested-1'>
</label>
<label for="checkbox-nested-2">2 Queen
<input type="checkbox" name="checkbox-nested-2" id="checkbox-nested-2">
</label>
</div>
<!-- </fieldset> -->
<br>
<button id='add_checkbox'>
add_checkbox
</button>
CSS
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
color:#fff;
}
#banner-message {
background: #fff;
border-radius: 4px;
padding: 20px;
font-size: 25px;
text-align: center;
transition: all 0.2s;
margin: 0 auto;
width: 300px;
}
button {
background: #0084ff;
border: none;
border-radius: 5px;
padding: 8px 14px;
font-size: 15px;
color: #fff;
}
#banner-message.alt {
background: #0084ff;
color: #fff;
margin-top: 40px;
width: 200px;
}
#banner-message.alt button {
background: #fff;
color: #000;
}
JavaScript
$( function() {
$( "#checkbox_block input" ).checkboxradio();
} );
$("#add_checkbox").click( function() {
var add = '<label for="checkbox-nested-3">3 Queen<input type="checkbox" name="checkbox-nested-3" id="checkbox-nested-3"></label>';
$("#checkbox_block").append(add);
$( "#checkbox_block input" ).checkboxradio();
});