М.б. как-то так?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.selected { color: red;};
</style>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
</head>
<body>
<li style=" clear:both;" class="magic-select">
<div class="subclass">
<label class="group-label">
<button type="button" id="g-161-xf_1" class="select exfield exgroup1 label_block switch-target opened" href="#" onclick="jaMagicSelect(this, 'mg-161-xf_1'); return false;" title="Район">Район (0)
</button>
</label>
<div class="ja-magic-select" id="mg-161-xf_1" data-autofilter="0" style="display: block;">
<ul>
<li rel="2" class="active">Автозаводский</li>
<li rel="3" class="active selected">Канавинский</li>
<li rel="4" class="active">Ленинский</li><li rel="5" class="active">Московский</li>
<li rel="6" class=" active">Нижегородский</li>
<li rel="7" class=" active">Приокский</li>
<li rel="8" class=" active">Советский</li><li rel="9" class=" active">Сормовский</li>
</ul>
<span class="btn-close">Close</span><span class="arrow"> </span></div><div id="mg-161-xf_1-container" class="ja-magic-select-container">
<span id="mg-161-xf_1-3">Канавинский<input type="hidden" name="xf_1[]" value="3">
<span rel="3" class="remove" title="Remove"></span></span></div>
</div>
</li>
<script>
document.querySelector(".ja-magic-select").addEventListener('click', leng);
function leng(event){
event.target.classList.toggle("selected");
var but = document.querySelector("#g-161-xf_1");
but.textContent = but.textContent.replace(/\d+/, document.querySelectorAll(".ja-magic-select li.selected").length);
}
var stEl = document.querySelector(".ja-magic-select .selected");
stEl.click(); stEl.click();
</script>
</body>
</html>