Add 'this' to the function called by anchor link event onclick
<a onclick="myAccFunc(this)" href="#">First group<i class="fa fa-caret-down"></i></a>
Then you need to ref that specifically clicked element, transverse down to next sibling element and change that elements classname
function myAccFunc(elem)//amended by dsonesuk
{
var x = elem.nextElementSibling;//amended by dsonesuk
if (x.className.indexOf("w3-show") == -1)
{
x.className += " w3-show";
x.previousElementSibling.className += " w3-green";
}
else
{
x.className = x.className.replace(" w3-show", "");
x.previousElementSibling.className =
x.previousElementSibling.className.replace(" w3-green", "");
}
}