I'm trying to implement HTML radio button behaviour on a set of DIVs in JQuery. I want to remove the "set" class from all the elements then use addClass() to re-set the (one) element that is clicked:
$(".button").each(function() {
$(this).click(function(){
// what goes here to call removeClass() on *all* the elements?
$(this).addClass("set");
});
});
I want to call removeClass() on all the elements - in this case $(".button"), but I can't refer to $(".button") explicitly.
I can't just call $(".button").removeClass("set") outside the loop as this is part of a bigger program and the behaviour inside the each() loop can be modified by other parameters.
Is there any way to access the full set of elements from inside, or pass them in as a variable? Or is there another way to approach the problem?