Is there a way to toggle the class selected
that is currently set on the button in .ProductItem-gallery-slides
to the corresponding button in .ProductItem-gallery-thumbnails
with the same data
attribute?
JavaScript
x
13
13
1
<div class="ProductItem-gallery-scroll">
2
<div class="ProductItem-gallery-thumbnails">
3
<button class="ProductItem-gallery-thumbnails-item" data-thumbnail-index="1"> Hello 1 </button>
4
<button class="ProductItem-gallery-thumbnails-item" data-thumbnail-index="2"> Hello 2 </button>
5
<button class="ProductItem-gallery-thumbnails-item" data-thumbnail-index="3"> Hello 3 </button>
6
</div>
7
</div>
8
9
<div class="ProductItem-gallery-slides" data-animation-role="image" data-product-gallery="slides">
10
<button class="ProductItem-gallery-slides-item selected" data-slide-index="1"> Good bye 1</button>
11
<button class="ProductItem-gallery-slides-item" data-slide-index="2">Good bye 2</button>
12
<button class="ProductItem-gallery-slides-item" data-slide-index="3">Good bye 3</button>
13
</div>
Advertisement
Answer
Whilst I agree with Rory – I suspect there is no example code so I hope the following is what you’re after:
JavaScript
1
6
1
$('.ProductItem-gallery-thumbnails-item').on('click',function(){
2
$('.ProductItem-gallery-slides-item').removeClass('selected');
3
4
$('.ProductItem-gallery-slides-item[data-slide-index="'+$(this).data('thumbnail-index')+'"]').addClass('selected');
5
})
6