JSFiddle - React, Tailwind, and code Playground

by oduska

HTML

<div class="form-group">
    <div class="checkbox">
        <input id="blah" type="checkbox" />
        
        <label for="blah" class="control-label col-md-3">
            Certificate of Assured Recycling
        </label>
        
        <input name="name" id="name" value="9" type="hidden" />
    </div>
</div>

CSS

body { font-family: arial; font-size: 14px; }

/**************************************************************/

input[type="checkbox"] { display: none; }

label { cursor: pointer; }

.check {
    display: inline-block;
    width: 14px; height: 14px;
    border: 2px solid #ccc;
    border-radius: 3px;
    vertical-align: middle;
}

.checked {
    border-color: red;
    position: relative;
}

.checked:before {
    content: "X";
    position: absolute;
    top: -1px; left: 2px;
    font-weight: bold;
}

JavaScript

$(":checkbox").before("<span class='check'></span>");
    
$(":checkbox").change(function(){
    if($(this).is(":checked")) {
        $(this).prev(".check").addClass("checked");
    } else {
        $(this).prev(".check").removeClass("checked");
    }
});