Know that this is an older stream, but you need a solution to convert checkboxes to images - and that was the best answer. :) So we reorganized it and wanted to share it.
function setCheckboxImageSrc(checkbox, image, checkedUrl, uncheckedUrl) {
if (checkbox.is(":checked")) {
image.attr("src", checkedUrl);
} else {
image.attr("src", uncheckedUrl);
}
}
function setCheckboxImage(checkboxObj, className, checkedUrl, uncheckedUrl) {
checkboxObj.hide();
var $image = $("<img src='" + checkedUrl + "' />").insertAfter(checkboxObj);
setCheckboxImageSrc(checkboxObj, $image, checkedUrl, uncheckedUrl);
$image.click(function () {
var $checkbox = $image.prev("." + className);
$checkbox.click();
setCheckboxImageSrc($checkbox, $image, checkedUrl, uncheckedUrl);
});
}
$(".checkboxUp").each(function () {
setCheckboxImage($(this), "checkboxUp", "../../../images/DirectionUpChecked.png", "../../../images/DirectionUpUnchecked.png");
});
$(".checkboxDown").each(function () {
setCheckboxImage($(this), "checkboxDown", "../../../images/DirectionDownChecked.png", "../../../images/DirectionDownUnchecked.png");
});
source
share