To check for prev(), next() element?

It is necessary to isolate the active element(the one upper).
The problem with 1ым and the last element.
How to check: when you click not left
if (.block.active is first).active add to the last element and Vice versa?

https://jsfiddle.net/xpycm789/j9z1g35o/6/
April 7th 20 at 10:40
2 answers
April 7th 20 at 10:42
Solution
<button data-step="-1">left</button>
<button data-step="+1">right</button>

let pos = 0;

const
 $slider = $('.slider'),
 $blocks = $slider.find('.block'),
 len = $blocks.length;

$('[data-step]').click(function() {
$blocks.filter('.active').removeClass('active');

 pos = pos + +this.dataset.step;
 $slider.css('transform', 'rotate(' + pos * 360 / len + 'deg)');

 $blocks.eq (((pos % len) + len) % len).addClass('active');
});
Thank you! - Aileen27 commented on April 7th 20 at 10:45
April 7th 20 at 10:44
use the :first/:last / :first-child/:last-child

Find more questions by tags jQuery