I want to add a class to multiple span elements with common classname's based on the classname of a link that is being clicked. This works for me only for the first element (1). The rest gives no result (also no error). Here is the code I'm trying to get functional, first HTML then the jQuery part:
<ul id="brancheNav">
<li><a href="#" class="brancheTab" id="brancheTab1">Duurzaam</a></li>
<li><a href="#" class="brancheTab" id="brancheTab2">B-to-B</a></li>
<li><a href="#" class="brancheTab" id="brancheTab3">Healthcare</a></li>
<li><a href="#" class="brancheTab" id="brancheTab4">Dienstverlening</a></li>
</ul>
<div class="opdrachtgevers">
<p>
<span class="branche1">ADFSDFSDF</span>
<span class="branche1">IUYIUYIU</span>
<span class="branche1">CVCBVCV</span>
<span class="branche4">MNBBMNBMB</span>
</p>
</div>
$("a.brancheTab").click(function(){
sClickedId = $(this).attr('id');
sId = sClickedId.substr((sClickedId.length - 1),1);
//alert('addClass: ' + sId);
$('span.branche'+sId).addClass('active');
});