$('.btns .next').click(function(){
if ($(this).hasClass("di")) {what = "div";}
else{what = "img";}
...
var xlen = $(c).find('>' + what).length;
});
这对 div
中的 first-level-children
进行计数,它可以工作,但有没有办法说:
var xlen = $(c).find('> whatever_is_first_child_of_c' ).length;
所以,无论第一个 child 是 img
或 div
或 p
或任何东西 - 我需要计算它们。
最佳答案
试试这个:
$('.wrapper >') // where wrapper is container or parent element
关于jquery - 计算任何标签的第一级子元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23447141/