JSFiddle - React, Tailwind, and code Playground
by Manan Patel
HTML
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<div class="taglist">
<label class="label_check" for="checkbox-01" id="lbl-box-posts1">
<input name="ck-box-posts[]" id="checkbox-01" class="chkBX" value="1" type="checkbox" />2D Animation</label>
<br />
<label class="label_check" for="checkbox-02" id="lbl-box-posts2">
<input name="ck-box-posts[]" id="checkbox-02" class="chkBX" value="2" type="checkbox" />3D Animation</label>
<br />
<label class="label_check" for="checkbox-03" id="lbl-box-posts3">
<input name="ck-box-posts[]" id="checkbox-03" class="chkBX" value="3" type="checkbox" />Animatronics</label>
<br />
<label class="label_check" for="checkbox-04" id="lbl-box-posts4">
<input name="ck-box-posts[]" id="checkbox-04" class="chkBX" value="4" type="checkbox" />Architectural</label>
<br />
<label class="label_check" for="checkbox-05" id="lbl-box-posts5">
<input name="ck-box-posts[]" id="checkbox-05" class="chkBX" value="5" type="checkbox" />Cartoon</label>
<br />
<label class="label_check" for="checkbox-06" id="lbl-box-posts6">
<input name="ck-box-posts[]" id="checkbox-06" class="chkBX" value="all" type="checkbox" onchange="toggle_chkbox(this,'ck-box-posts[]','lbl-box-posts');" />Check All</label>
<br />
<input type="text" name="textValue" id="textValue">
</div>
CSS
.has-js .label_check, .has-js .label_radio {
padding-left: 34px;
}
.has-js .label_check {
background: url(http://webdesign.maratz.com/lab/fancy-checkboxes-and-radio-buttons/check-off.png) no-repeat;
}
.has-js label.c_on {
background: url(http://webdesign.maratz.com/lab/fancy-checkboxes-and-radio-buttons/check-on.png) no-repeat;
}
.has-js .label_check input, .has-js .label_radio input {
position: absolute;
left: -9999px;
}
JavaScript
$.noConflict();
function toggle_chkbox(source, group, lbl) {
checkboxes = document.getElementsByName(group);
for (var i = 0; i < checkboxes.length; i++) {
var chkid = '#' + lbl + i;
checkboxes[i].checked = source.checked;
if ($(chkid).hasClass('c_on') && checkboxes[i].checked == false) {
$(chkid).removeClass('c_on').addClass('c_off');
} else if ($(chkid).hasClass('c_off') && checkboxes[i].checked == true) {
$(chkid).removeClass('c_off').addClass('c_on');
}
}
updateTextArea();
}
function updateTextArea() {
var allVals = [];
$('.taglist :checked').each(function (i) {
allVals.push((i != 0 ? "" : "") + $(this).val());
});
$.cookie("example", allVals, {
expires: 1
});
$('#textValue').val(allVals).attr('rows', allVals.length);
}
$(function () {
$('.taglist input').click(updateTextArea);
});
var d = document;
var safari = (navigator.userAgent.toLowerCase().indexOf('safari') == 1) ? true : false;
var gebtn = function (parEl, child) {
return parEl.getElementsByTagName(child);
};
$.noConflict();
$(document).ready(function () {
var body = gebtn(d, 'body')[0];
body.className = body.className && body.className != '' ? body.className + ' has-js' : 'has-js';
if (!d.getElementById || !d.createTextNode) return;
var ls = gebtn(d, 'label');
for (var i = 0; i < ls.length; i++) {
var l = ls[i];
if (l.className.indexOf('label_') == -1) continue;
var inp = gebtn(l, 'input')[0];
if (l.className == 'label_check') {
l.className = (safari && inp.checked == true || inp.checked) ? 'label_check c_on' : 'label_check c_off';
l.onclick = check_it;
};
if (l.className == 'label_radio') {
l.className = (safari && inp.checked == true || inp.checked) ? 'label_radio r_on' : 'label_radio r_off';
l.onclick = turn_radio;
};
};
});
var check_it...