toggleClass messing something up.
- by Mathias Nielsen
Hi
I am using playing around with the Pretty-checkboxes-plugin and have a problem.
The plugin can be seen here http://aaronweyenberg.com/90/pretty-checkboxes-with-jquery
As you can see, this uses two links to select and deselect. I want it to only use one link and then change the class to make it work the other way the next time it is clicked.
It should be simple enough. I have been trying to get it working with toggleClass.
I simply put in the toggleClass statement so the code looks like so:
$(document).ready(function() {
/* see if anything is previously checked and reflect that in the view*/
$(".checklist input:checked").parent().addClass("selected");
/* handle the user selections */
$(".checklist .checkbox-select").click(
function(event) {
event.preventDefault();
$(this).parent().addClass("selected");
$(this).parent().find(":checkbox").attr("checked","checked");
$(this).toggleClass("checkbox-select checkbox-deselect");
}
);
$(".checklist .checkbox-deselect").click(
function(event) {
event.preventDefault();
$(this).parent().removeClass("selected");
$(this).parent().find(":checkbox").removeAttr("checked");
$(this).toggleClass("checkbox-select checkbox-deselect");
}
);
});
This works to some extend. The classes toggle just fine, but the rest of the code only works the first time it is run. All subsequent clicks just toggle the class og the link and nothing else.
Does anyone have any idea why this is?