ID -
уникальный идентификатор.
<div class="spans-container">
<span>Текст 1.</span><br>
<span>Текст 2.</span><br>
</div>
<style>.spans-container span.highlighted{font-size:13pt;font-weight:bold;background:#D9FFAD;}</style>
<script>
const container = document.querySelector('.spans-container');
const activeClass = 'highlighted';
container.addEventListener('click', function(e) {
const target = e.target;
if (!target || target.tagName.toLowerCase() !== 'span')
return;
if (target.classList.contains(activeClass))
return void target.classList.remove(activeClass);
const activeElement = container.querySelector('.' + activeClass);
if (activeElement)
activeElement.classList.remove(activeClass);
target.classList.add(activeClass);
});
</script>