Reputation: 2737
I am using a usercontrol in which a gridview with html checkboxes are present.I am using this control in another page. Some of these checkboxes comes checked when the user control in the page is loaded.
So in order to change the style of checkboxes when the usercontrol loads, this is the jquery code I have added in a js file,
<input type="checkbox" class="chk">
jQuery('input:checkbox.chk').click(evaluate).each(evaluate);
function evaluate() {
debugger;
var item = jQuery(this);
alert('hello');
if (item.is(":checked")) {
jQuery(this).parent().toggleClass("active");
} else {}
}
But this is not firing at all. what's wrong in the code. Can any one please help me out in solving this.
Any help is appreciated. Thanks.
Upvotes: 0
Views: 270
Reputation: 179
May be you miss $(document).ready
$(document).ready(function(){
// Put your code here
})
Upvotes: 2
Reputation: 28823
Move this code to pageinit function of first page or document.ready event.
if (item.is(":checked")) {
jQuery(this).parent().toggleClass("active");
}
else {
}
Upvotes: 1
Reputation: 148120
There are three things to do
Binding event,
$(document).ready(function(){
jQuery('input:checkbox.chk').change(evaluate);
});
Defining function
function evaluate() {
debugger;
var item = jQuery(this);
alert('hello');
if (item.is(":checked")) {
jQuery(this).parent().toggleClass("active");
} else {
}
}
Upvotes: 1