var addBasketEL = $('.js-btnBasket');
var selectedContainerEL = $('.js-selectedContainer');
// Cards Content
var cardImageEL = $('.js-cardImage');
var cardCategoryEL = $('.js-cardCategory');
var cardNameEL = $('.js-cardName');
var cardPriceEL = $('.js-cardPrice');
function addSelectedCard(e) {
e.append(`
<article class="selected-card js-selectedCard">
<div class="selected-card__image">
${cardImageEL.html()}
</div>
<div class="selected-card__text">
<a href="#" class="cards__category">${cardCategoryEL.text()}</a>
<h2 class="selected-card__name">
${cardNameEL.html()}
</h2>
</div>
<span class="price selected-card__price">${cardPriceEL.text()}</span>
<button class="btn__delete js-btnDelete"></button>
</article>
`);
}
// Program Execution
$(function () {
addBasketEL.click(function () {
if (selectedContainerEL.length) {
$('.js-selectedCard').remove();
$('button').removeClass('active');
addSelectedCard(selectedContainerEL);
$(this).addClass('active');
} else {
addSelectedCard(selectedContainerEL);
$(this).addClass('active');
}
$('.js-btnDelete').click(function () {
$(this).parent().remove();
});
});
});
$(function () {
addBasketEL.click(function () {
if (selectedContainerEL.length) {
$('.js-selectedCard').remove();
$('button').removeClass('active');
addSelectedCard(selectedContainerEL);
$(this).addClass('active');
} else {
addSelectedCard(selectedContainerEL);
$(this).addClass('active');
}
$('.js-btnDelete').click(function () {
$(this).parent().remove();
});
});
});