Reputation: 1643
Trying to change the background color of a label for a checkbox when the checkbox is checked. I can do it using this method http://jsfiddle.net/CjpmP/ but I can find figure out how to do it with the @html.checkbox and the label for method I need to use. Here is what I've got
<style type="text/css">
.checkyoself{
display: none;
}
.checkyoself:checked + .label1{
background-color: green;
}
.label1 {
width: 240px;
height: 140px;
margin-right: 5px;
margin-left: 5px;
margin-top: 5px;
margin-bottom: 5px;
padding: 5px;
color: #ffffff;
background-color: #9e00f2;
float: left;
}
</style>
@{
var j = 0;
using (Html.BeginForm("GroceryList", "RecipeIngredient", FormMethod.Post))
{
for (int i = 0; i < @Model.RecipeItems.Count; i++)
{
var name = "check_" + j;
@Html.CheckBoxFor(itemModel => itemModel.RecipeItems[i].IsChecked, new { id = @name, @class="checkyoself" })
<label for=@name class="label1">@Model.RecipeItems[i].Recipe.Title</label>
@Html.HiddenFor(itemModel => itemModel.RecipeItems[i].Recipe.Title)
j++;
}
}
}
Upvotes: 0
Views: 539