Click here to Skip to main content
15,894,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have one foreach loop under foreach I have one

tage under

tag one input checkbox. In that loop their is 5 items. And

tags created 5 times. Now when I check suppose 4th item then I want to highlighted only 4th

tag with red color. How to implement? I have attached foreach loop code. And I have use MVC4.



@foreach (SelectListItem item in ViewBag.LocationList)
{


<input type="checkbox" id="chkLocations"
class="check"/>


}
Posted
Comments
Member 10530640 1-Sep-14 2:58am    
Please show me the code

hi,

Surround your Input tag with a division and give a ID (id should be same as the ID of your check box with some prefix)
e.g. If your Check box id is 1 then make your Div id as DIV_1.

Then using j query on click event of the check box first check weather the check box is checked or not based on that form the Division id using check box ID and set the back ground color of the division.
 
Share this answer
 
use Label and CSS for achiving the same
as
JavaScript
@foreach (SelectListItem item in ViewBag.LocationList)
        {

        <input type="checkbox" id="_@item.key">
               class="check" />
        <label for="_@item.key">TAG</label>
        }


CSS:
CSS
input[type=checkbox] + label {
            color: #ccc;
            font-style: italic;
        }

        input[type=checkbox]:checked + label {
            color: white;
            font-style: normal;
            background-color:red;
        }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900