javascript - how add class in selected images in slide show? -


when click on thumb image, want selected thumb image, here when click other thumb image previous thumb image remain selected

css code:

.imgstyle:hover {       border-color: black; } .imgstyle {     height: 100px;     width: 100px;     border: 2px solid grey; } .active {     border-color: red; } 

//js code

$(document).ready(function () {     $('#divcontainer img').on('click', function () {          $(this).addclass('active');          var imgurl = $(this).attr('src');          $('#mainimage').fadeout(1000, function () {             $(this).attr('src', imgurl);         }).fadein(1000);      }); });  

html:

<img id="mainimage" src="images/chrysanthemum.jpg" width="540" height="500" style="border:3px solid grey">  <br/> <div id="divcontainer">     <img class="imgstyle" src="images/chrysanthemum.jpg" />     <img class="imgstyle" src="images/desert.jpg" />     <img class="imgstyle" src="images/hydrangeas.jpg" />     <img class="imgstyle" src="images/jellyfish.jpg" />     <img class="imgstyle" src="images/koala.jpg" />  </div> 

remove active class siblings of clicked image

$(document).ready(function() {    $('#divcontainer img').on('click', function() {      $(this).addclass('active').siblings('img').removeclass('active');      var imgurl = $(this).attr('src');      $('#mainimage').fadeout(1000, function() {        $(this).attr('src', imgurl);      }).fadein(1000);    });  });
.imgstyle:hover {    border-color: black;  }  .imgstyle {    height: 100px;    width: 100px;    border: 2px solid grey;  }  .active {    border-color: red;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>  <img id="mainimage" src="images/chrysanthemum.jpg" width="540" height="500" style="border:3px solid grey">  <br/>  <div id="divcontainer">    <img class="imgstyle" src="images/chrysanthemum.jpg" />    <img class="imgstyle" src="images/desert.jpg" />    <img class="imgstyle" src="images/hydrangeas.jpg" />    <img class="imgstyle" src="images/jellyfish.jpg" />    <img class="imgstyle" src="images/koala.jpg" />  </div>


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -