Click here to Skip to main content
15,886,847 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
@model IEnumerable<dmart.categorydetailsmaster>

<script src="~/Scripts/jquery-1.8.2.js"></script>
<script src="~/Scripts/jquery-1.8.2.min.js"></script>


@Html.DisplayNameFor(model => model.CategoryName)
@foreach (var item in Model)
{

<input type="checkbox" id="catAll"/>
@Html.DisplayFor(modelItem => item.CategoryName)


}
<script type="text/javascript">
$(document).ready(function(){

$("[.treename] input[type=checkbox]").bind("click", function () {
var $this = $(this)
if($this.next().length > 0 && $this.next()[0].tagName == "DIV")
{
var isChecked = $(this).is(":checked");
if(isChecked)
{
$(this).attr("checked", "checked");
}
else {
$(this).removeAttr("checked");
}
}
});
});
</script>
Posted
Updated 12-Aug-15 1:34am
v2
Comments
Sanket Saxena 12-Aug-15 7:37am    
First remove the multiple reference of jQuery 1.8.2. If not necessary(debug not required) then use the minified one.
Secondly, Paste your rendered HTML.
Nandu Nair 12-Aug-15 7:44am    
Thnx for reply sir, but i am new to MVC and jquery.
So plz can u xplain me in detail.

1 solution

You can get the id of clicked element by using below line
JavaScript
var idOfElement=$(this).attr("id");


In the above code, you referenced jQuery multiple time so please use only minimized version. Otherwise it will make your site loading a bit slow.

HTML
<script src="~/Scripts/jquery-1.8.2.js"></script>
<script src="~/Scripts/jquery-1.8.2.min.js"></script>

Remove below line
HTML
<script src="~/Scripts/jquery-1.8.2.js"></script>
 
Share this answer
 

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