I am utilizing a series of div elements that can be triggered with the following code snippet:
$(".course_id").on("click", function(){
var id = $(this).data("id");
$("div#lessons_by_course_" + id).removeClass("hidden");
});
The div elements are assigned with an id like lessons_by_course + id, for example:
<div id="lessons_by_course1"></div>
The ID number is dynamically generated using a Ruby on Rails .each loop.
My goal is to have only one div visible at a time. So when I click on a certain div, I want it to display and hide the previously shown div. This way, only the clicked div will be visible.
Keep in mind that .course_id is a class applied to multiple elements, causing different divs to appear each time one of them is clicked due to the unique ID being utilized for each element.