admin管理员组文章数量:1025321
Trying to convert some jQuery to javascript. Was using this for jQuery:
var list = $('.list li'),
listLength = list.length;
Now I'm trying it with JS, but it doesn't seem to work:
var list = document.querySelector(".list"),
listLi = list.getElementsByTagName("li"),
listLength = listLi.length;
Any ideas?
Trying to convert some jQuery to javascript. Was using this for jQuery:
var list = $('.list li'),
listLength = list.length;
Now I'm trying it with JS, but it doesn't seem to work:
var list = document.querySelector(".list"),
listLi = list.getElementsByTagName("li"),
listLength = listLi.length;
Any ideas?
Share Improve this question asked Jan 8, 2013 at 7:16 user1929705user1929705 211 silver badge8 bronze badges 3- 2 Works just fine for me - jsfiddle/gWvCQ – Andreas Commented Jan 8, 2013 at 7:20
- 1 Your Vannila JS code works just fine. – Sandeep Commented Jan 8, 2013 at 7:22
- 1 Yeah, thanks, just had a typo in the actual code. Oops! – user1929705 Commented Jan 8, 2013 at 7:25
1 Answer
Reset to default 3Your code should already work. But you can also use document.querySelectorAll()
to perform a selector match which is cleaner than the two separate calls:
var listLi = document.querySelectorAll(".list li"),
listLength = listLi.length;
Trying to convert some jQuery to javascript. Was using this for jQuery:
var list = $('.list li'),
listLength = list.length;
Now I'm trying it with JS, but it doesn't seem to work:
var list = document.querySelector(".list"),
listLi = list.getElementsByTagName("li"),
listLength = listLi.length;
Any ideas?
Trying to convert some jQuery to javascript. Was using this for jQuery:
var list = $('.list li'),
listLength = list.length;
Now I'm trying it with JS, but it doesn't seem to work:
var list = document.querySelector(".list"),
listLi = list.getElementsByTagName("li"),
listLength = listLi.length;
Any ideas?
Share Improve this question asked Jan 8, 2013 at 7:16 user1929705user1929705 211 silver badge8 bronze badges 3- 2 Works just fine for me - jsfiddle/gWvCQ – Andreas Commented Jan 8, 2013 at 7:20
- 1 Your Vannila JS code works just fine. – Sandeep Commented Jan 8, 2013 at 7:22
- 1 Yeah, thanks, just had a typo in the actual code. Oops! – user1929705 Commented Jan 8, 2013 at 7:25
1 Answer
Reset to default 3Your code should already work. But you can also use document.querySelectorAll()
to perform a selector match which is cleaner than the two separate calls:
var listLi = document.querySelectorAll(".list li"),
listLength = listLi.length;
本文标签: javascriptHow to get the length of an ordered listStack Overflow
版权声明:本文标题:javascript - How to get the length of an ordered list? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745619053a2159464.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论