You add the class to the entire accordion_list element collection, but you need to add it to the current iterative element.
$(".prime-content .accordion-body").each(function(index, element){ $(element).addClass(index == 0 ? "in" : ""); });
If you do nothing in the loop, you can also make it shorter:
accordion_list.first().addClass("in");
source share