I have a collection of checkboxs and I want to create a custom method for them depending on which class they have.
var checkboxs = $("input[type=checkbox]");
checkboxs.each(function(){
if($(this).hasClass("class1")){
$(this).method1 = function(){
$(this).removeAttr("checked");
return $(this);
}
}
if($(this).hasClass("class2")){
$(this).method1 = function(){
$(this).parents("tr").next().hide();
$(this).removeAttr("checked");
return $(this);
}
}
});
Then if, I want to do this:
checkboxs.each(function(){
$(this).method1();
});
It tells me that there's no method1 method. Why doesn't that work?