Im using garlic.js to save input states of checkboxes (http://garlicjs.org/). It works great, but for some reason, jQuery doesn't recognise when the input is checked by garlic.js after a page reload.
Im probably missing something here, but not sure what it is.
If for example I set #myInput:checked ~ .wonka {width: 200px}
in my stylesheet, Css recognize it and apply the style to .wonka
every time the page load and the input get its value by garlic. Of course, using a sibling selector is very limiting (I cannot do that if the class is on the body, for example).
Doing something similar in jQuery, doesn't work:
// This is not working
if ($("#myInput").is(":checked")) {
$("body").addClass("wonka");
}
// Neither this
if ($("#myInput").attr("checked")==true) {
$("body").addClass("wonka");
}
Note: This is suposed to inmediatly fire as the page is loaded or refresh, not when is clicked by the user. The point is to fire it again when the page is refresh (or loaded from other tab), that way it would be the same as it was after the refresh.
I do can fire other events when the checkbox is "clicked" or "hover". Like this, for example:
$("#myInput").on("change", function(){
$("body").addClass("wonka");
});
But, again, this is not the problem. Why jQuery doesn't recognize the input state?, im using the wrong code?