To count the number of elements with a class of "top" using jQuery and perform an action if the count is zero, you can use the following code:

var topCount = $('.top').length;

if (topCount === 0) {
   // Perform your desired action here
   console.log("No elements with class 'top' found.");
}

This code selects all elements with the class "top" using the jQuery selector $('.top') and retrieves the count using the .length property. If the count is equal to zero, it executes the specified action, which in this example is printing a message to the console.

Modify the action inside the if statement according to your requirements

qq_comment_datai want to count top as jquery class and if its equal to 0 if have to do something

原文地址: https://www.cveoy.top/t/topic/ikeZ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录