I have a method that I want to take some action depending on the 'checked' status of a checkbox. The 'click' event works as expected, but the 'myFunction' call in the foreach loop does not:
$(document).ready(function(){
$('#TreeView1 :checkbox')
.click(HandleCheckbox); // Works fine
// Go through the entire Category treeview to
// see if there are any checkboxes that are already
// checked.
$.fn.myFunction = HandleCheckbox;
$(":checked:checkbox").each(function(index) {
// In the HandleCheckbox 'this' is undefined.
$(this).myFunction();
});
});
function HandleCheckbox() {
alert(this.name + '=' + this.checked);
}
In the above code, when the '.click' method fires, 'this' is defined, as expected. When I call 'muFunction' in the foreach loop, 'this' is undefined in the 'HandleCheckbox' function.
I am still learning the jQuery ropes, so if there is a 'better' or easier way of doing this, please let me know.
Thanks.