Здравствуйте! Помоги с кодом переписать на чистый JS?
Сам код:
$(document).ready(function () {
$('.card__item').click(function (e) {
e.preventDefault;
if (e.target.classList == 'card__button'){
$(this).closest('.card__item').addClass('active');
$(this).closest('.card__item').find('.card__block').slideUp();
$(this).closest('.card__item').find('.card__booked').slideDown();
$(this).off("mouseleave");
return
}
$(this).mouseleave(function () {
$(this).closest('.card__item').removeClass('active');
$(this).find('.card__block').slideDown();
$(this).find('.card__booked').slideUp();
})
});
});
мои попытки:
const cards = document.querySelector('.card__items'),
card = document.querySelectorAll('.card__item'),
cardBlock = document.querySelectorAll('.card__block'),
cardBooked = document.querySelectorAll('.card__booked');
cards.addEventListener('click mouseout', (event) => {
let target = event.target;
if (target && target.classList.contains('card__button')) {
this.closest(card).classList.add('active');
this.closest(card).find(cardBlock).slideUp();
this.closest(card).find(cardBooked).slideDown();
this.removeEventListener("mouseleave");
return
}
document.querySelector(this).mouseleave(function () {
this.removeClass('active');
this.cardBlock.slideDown();
this.cardBooked.slideUp();
})
});