我想将childElementCount与jQuery一起使用,所以有什么方法可以检查吗?
这是可以使用的javascript代码:
var box = document.getElementById('list_items').childElementCount;
alert(box);
但是为什么这不适用于jQuery。
var box = $('list_items').childElementCount;
我在这里找到了stackoverflow帖子:
但它显示:
var count = $(result).find('RESULTS').first().children().length;
也许然后使用此代码javascript是个好方法,但是我还想与jQuery一起使用其他DOM属性。
您正在对jQuery对象调用DOM属性。您必须获取嵌入在jQuery对象中的DOM元素:
var box = $('#list_items').get(0).childElementCount;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句