I want to use images to create a custom checkbox. I know how to do this, and there are a lot of great alternatives on this site. But my number one goal here is learning so I would like to ask this question. When I hide the HTML checkbox with CSS using display: none; the jquery code doesn't work anymore. And that makes sense to me, but how can I make it so the custom checkbox with the images also functions like the original one?
HTML
<div id="togglecontainer">
<input type="checkbox" id="checkbox'+(counter)+'"class="item"/>
<label for="checkbox"></label>
<input value="make me bold" type="text" class="inputfield"/>
</div>
CSS
.inputfield{
padding-left: 20px;
}
label:before {
content: url("https://cdn1.iconfinder.com/data/icons/windows8_icons_iconpharm/26/unchecked_checkbox.png");
position: absolute;
z-index: 100;
}
input[type=checkbox]:checked+label:before {
content:url("https://cdn1.iconfinder.com/data/icons/windows8_icons_iconpharm/26/checked_checkbox.png");
}
input[type=checkbox] {
//display: none;
}
.complete {
font-weight: bold;
}
input[type=text] {
background-color:transparent;
border: 0px solid;
margin-left: 20px;
color:#222222;
font-size: 13px;
}
jQuery
$("#togglecontainer").delegate("input[type=checkbox]", "change", function () {
$(this).nextAll().toggleClass("complete");
});
P.s. A little side question; as you can see this fiddle uses an older version of jQuery. When I link to a newer version the whole thing doesn't work anymore. Can someone elaborate on that a little as well?
Thanks in advance.