I have a menu that contains a bunch of toggles. Each item toggles something different.
I am trying to make an overall "reset" button that resets several things back to some default settings. I need to detect if a menu item is toggled or not, and if so, execute some code on that particular item and if not, do nothing. With an item is toggled on, it gets a CSS background color, demonstrated below, so I came up with the following reset code:
$('#app-menu ul.dynamic-items li ul li').toggle(function () {
$(this).css({background: "#4c581e"});
}, function () {
$(this).css({background: "none"});
});
/* Reset Button */
$(".reset").click(function() {
if( $('#app-menu ul.dynamic-items li').css({background: "#4c581e"}) != null ) {
$(this).click(); /* If the item has the background code mentioned above, it is toggled on, therefore this "click" should reset its state */
}
else {
// do nothing //
};
});
Basically I am trying to say that, if a menu item has the #4c581e background, that means its toggled on, and therefore it should be "clicked" to toggle it off again.
Problem is, its not working. I am fairly new-ish to jQuery so I figured I am doing something wrong.
Any ideas folks?
EDIT: I just want to note that the menu items actually toggle DIV elements on the page, so its not just a matter of resetting the menu item's css style. This is why I tried to make it "click" the item if the particular CSS property is detected, because "clicking" it will basically toggle it off again.