I am doing a image switcher, I was trying solutions applied there, but I can not help myself.
Very simple thing, I am trying to make a image switcher. Team members are changing after a click, and also class of the a member name from ""active-members-link" to the "members-link". Unfortunately I don't know why both doesn't work, please share your thoughts with me. I want to add more members in future so it can not be if statement.
Please vanilla Javascript.
<script>
function changeImage(img) {
let image = document.getElementById("ChangePic");
let currentAddres = document.getElementById("ChangePic").src;
image.src = img.src.replace("$currentAddres", "{{$site_url}img/{$this.innerHTML.jpg}");
let currentActive = document.getElementsByClass("active-members-link");
currentActive.class = "members-links";
this.class = "active-members-link";
}
</script>
<section class="fp-section margin-div">
<div class="fp-main-visual">
<img class="fp-main-visual__image fp-main-visual__image--pc ofi" src="{$site_url}img/big3.jpg" width="300" height="300" alt="{$cl_dat.cl_name}">
<img class="fp-main-visual__image fp-main-visual__image--sp ofi" id="changePic" src="{$site_url}img/John John.jpg" width="300" height="300" alt="{$cl_dat.cl_name}">
</div>
<div class="container after-article mx-auto">
<div class="row">
<div class="col-12 col-lg-6 text-center"><a class="active-members-link" href="" onclick="changeImage(this)">John John</a></div>
<div class="col-12 col-lg-6 text-center"><a class="members-links" href="" onclick="changeImage(this)">John2 John2</a></div>
</div>
</div>
</section>
Thank you
document.getElementsByClassand Element.className instead ofcurrentActive.class?