有没有办法使用jQuery获取类中的元素数?

有没有办法使用jQuery获取类中的元素数?,jquery,slider,Jquery,Slider,我正在尝试编写一个简单的jQuery滑块,需要找到特定类的元素数。有办法做到这一点吗 $(".classname").size() 我们应该做到这一点 使用以下属性: $('.yourClass').length 如果使用该属性,将跳过函数调用。该函数仅返回此.length var $elements = $('.classname'); // cache the result of your query var numberOfElements = $elements.length; //

我正在尝试编写一个简单的jQuery滑块,需要找到特定类的元素数。有办法做到这一点吗

$(".classname").size()
我们应该做到这一点

使用以下属性:

$('.yourClass').length
如果使用该属性,将跳过函数调用。该函数仅返回
此.length

var $elements = $('.classname'); // cache the result of your query
var numberOfElements = $elements.length; // slightly faster than .size()