I have a simple add attribute function:
$(\".list-toggle\").click(function() {
$(\".list-sort\").attr(\'colspan\', 6);
});
My question is:
This would be a good place to use a closure:
(function() {
var toggled = false;
$(".list-toggle").click(function() {
toggled = !toggled;
$(".list-sort").attr("colspan", toggled ? 6 : null);
});
})();
The toggled variable will only exist inside of the scope defined, and can be used to store the state of the toggle from one click event to the next.