使用jQuery查找可见元素的长度 [英] Find length of a visible elements using jQuery

查看:64
本文介绍了使用jQuery查找可见元素的长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我需要找到仅具有显示块的所有li元素的长度.使用jQuery如何做到这一点.我有一个类别菜单块,其底部具有更多链接,单击该链接将显示所有类别.底部链接现在变为``较少'',单击该链接可显示较少的项目. 这是代码.

Hi all I need to find the length of all the li elements which has display block only. How can this be possible using jQuery. I have a category menu block which has more link at the bottom which when clicked will displays the all categories.The Bottom link now turn to Less which when clicked displays less items. Here is the code.

var list = $('.menu-categories-list ul li:gt(3)');
        list.hide();
        $('#ClickMore').click(function() {
            list.slideToggle(400);
            if( $(this).parent().prev().children().length < 1 ) {
                $(this).html('Less...');
            }
            else {
                $(this).html('More...');
            }
            return false;
        });

您可以查看链接.类别位于左侧

YOu can have a look at the link. The categories block on the left side

推荐答案

我建议:

$('.menu-categories-list ul li:visible').size()

状况:

if ( $('.menu-categories-list ul li:visible').size() >= 4 ) {
    // do something
}

这篇关于使用jQuery查找可见元素的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆