Answer the question
In order to leave comments, you need to log in
How can this code be optimized?
There is a piece of code
$('.buy7').on('click', function(){
$('.bought7').fadeIn(600);
$('.tovar7').val($('.h27').text());
$(this).fadeOut();
});
$('.otmena7').on('click', function(){
$('.bought7, this').fadeOut(600);
$('.buy7').show();
});
$('.buy8').on('click', function(){
$('.bought8').fadeIn(600);
$('.tovar8').val($('.h28').text());
$(this).fadeOut();
});
$('.otmena8').on('click', function(){
$('.bought8, this').fadeOut(600);
$('.buy8').show();
});
Answer the question
In order to leave comments, you need to log in
Elementary after all cycle:
for (let i = 1; i<= 8; i++) {
$('.buy' + i).on('click', function(){
$('.bought' + i).fadeIn(600);
$('.tovar' + i).val($('.h2' + i).text());
$(this).fadeOut();
});
$('.otmena' + i).on('click', function(){
$('.bought' + i + ', this').fadeOut(600);
$('.buy' + i).show();
});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question