In your case, it failed to iterate over the buttons, you iterated only in div#botoes
, need to iterate over the children of that div that encompasses the buttons.
That way your code would look like:
$("#botoes div").each(function() {
$(this).click(function() {
$(".botaoativo").removeClass('botaoativo');
$(this).addClass('botaoativo');
});
});
JSFiddle of that solution.
Another way would be to iterate over the children, regardless of what they are, through the function children
:
$("#botoes").children().each(function() {
$(this).click(function() {
$(".botaoativo").removeClass('botaoativo');
$(this).addClass('botaoativo');
});
});
JSFiddle for this solution.