@winers
Начинающий программист

Почему выдаёт length только из последнего набора?

$(document).ready(function () {
    const quantityItem = $('.category2-content-body__items');
    quantityItem.each(function () {
        const item = $(this).children();
        $('.category2-accordion__title--js').html(item.length);
        console.log(item);
        console.log(item.length);
    });
});
вот что в консоле

jQuery.fn.init(6) [div.category2-content-item, div.category2-content-item, ....
 6
jQuery.fn.init(11) [div.category2-content-item, div.category2-content-item, ...
 11
jQuery.fn.init(6) [div.category2-content-item, div.category2-content-item, ...
 6
jQuery.fn.init(8) [div.category2-content-item, div.category2-content-item, ...
 8

в каждом title должен выводиться свой length, но выводит везде 8(последнего)
  • Вопрос задан
  • 67 просмотров
Решения вопроса 1
@westy
Если title лежит внутри item:
$(document).ready(function () {
    const quantityItem = $('.category2-content-body__items');
    quantityItem.each(function () {
        const item = $(this).children();
        $(this).find('.category2-accordion__title--js').html(item.length);
        console.log(item);
        console.log(item.length);
    });
});
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы