This is what I have tried, I think the question is self-explainatory.
Using CSS: (This did not work I did a jsfiddle)
.star + label{
background:url('image1.png') no-repeat;
height: 16px;
width: 16px;
display:inline-block;
padding: 0 0 0 0px;
}
.star:checked + label{
background:url('image2.png') no-repeat;
height: 16px;
width: 16px;
display:inline-block;
padding: 0 0 0 0px;
}
Using jQuery (This worked partially)
$('.star').replaceWith("<img src='image1.png' />");
$('.star').click(function () {
var $checkbox = $(this).prev(".star");
$checkbox.prop('checked', !$checkbox.prop('checked'));
if ($checkbox.prop("checked")) {
$image.attr("src", "image2.png");
} else {
$image.attr("src", "image1.png");
}
})
JSFIDDLE: fiddle
And this is my code on the aspx page:
<span>
<asp:CheckBox ID="star1" CssClass="star" runat="server" />
<asp:CheckBox ID="star2" CssClass="star" runat="server" />
<asp:CheckBox ID="star3" CssClass="star" runat="server" />
<asp:CheckBox ID="star4" CssClass="star" runat="server" />
<asp:CheckBox ID="star5" CssClass="star" runat="server" />
</span>
What could I be doing wrong? I have looked for multiple solutions (there are a lot of questions here about it) but they don't handle the case in which it is asp.NET.
class="star"with the image... then the next piece of code is not going to find any elements withclass="star"to bind to? Try putting theclass="star"as part of the<img>code you're using to replace$(".star").on("click", function() { ... });