I have some buttons, each with a class of "fullscreen-button", that I intend to use to show/hide content on a page. The buttons all have id's that are names of school programs, and there are divs for each button on the page with classes that match the id's (a button with an id of "programming" and a corresponding div with a class of "programming", etc).
My goal now is to have it so when a button is clicked, a div with a class that matches the id of the clicked button is hidden by giving that div a class that is styled to display:none.
I've written out some jQuery that I would expect does this, but it only manages to work for the first button so I know I'm going wrong somewhere. This is what I have at this point...
$('.fullscreen-button').each(function(i,elm) {
programTitle = $(elm).attr("id");
$(elm).click(function(){
$('.program-collector div').each(function(j,pelm) {
if ($(pelm).hasClass(programTitle)) {
$(pelm).addClass("hidden");
}
});
})
});
So, how do I actually loop through all of the buttons and divs properly?