Currently, I am working on a frontend project that involves jQuery. I have a list of names and I want to add a class of "selected" when one is clicked. However, if another name is selected, the class should be removed from the previously selected name and added to the new selection. Since there are multiple names, creating individual functions for each option is not feasible. Is there an easier way to achieve this functionality?
HTML
<ul class="names">
<li class="name selected">Name-1</li>
<li class="name">Name-2</li>
<li class="name">Name-3</li>
</ul>
CSS
.selected {
background-color: rgba(0, 0, 0, 0.3);
}