JavaScript
- 10 ответов
- 0 вопросов
5
Вклад в тег
(function() {
var contentReview = document.querySelectorAll('.reviews__text');
var moreBtnReview = document.querySelectorAll('.reviews__more');
var num = 120;
for (var i = 0; i < contentReview.length; i++) {
var bigTextReview = contentReview[i].innerHTML;
var cutTextReview = bigTextReview.slice(0, num);
moreBtnReview[i].style.display = 'none';
if (bigTextReview.length > num) {
moreBtnReview[i].style.display = '';
var vis = false;
var toggle1 = function(key) {
console.log(key);
if (!vis) {
contentReview[key].innerHTML = cutTextReview;
moreBtnReview[key].textContent = 'Подробнее';
vis = true;
} else {
contentReview[key].innerHTML = bigTextReview;
moreBtnReview[key].textContent = 'Скрыть';
vis = false;
}
};
moreBtnReview[i].addEventListener('click', function(key){return function(){toggle1(key);}}(i));
toggle1(i);
}
}
})();
moreBtnReview[i].addEventListener('click', function(key){return function(){toggle1(key);}}(i));