admin管理员组文章数量:1400660
I've got an ajax request that fetches an HTML string, like:
<div class="video">...</div><div class="video">...</div>
and I want to count the number of "video" div's as soon as I retrieve the HTML from the server. Is there an easy way to do this?
I tried:
.done(function(data) {
$(data).find('.video').length
but it returns 0.
I've got an ajax request that fetches an HTML string, like:
<div class="video">...</div><div class="video">...</div>
and I want to count the number of "video" div's as soon as I retrieve the HTML from the server. Is there an easy way to do this?
I tried:
.done(function(data) {
$(data).find('.video').length
but it returns 0.
Share Improve this question edited Jun 5, 2014 at 9:09 Mark 2,43511 gold badges31 silver badges50 bronze badges asked Jun 5, 2014 at 9:05 b0xxed1nb0xxed1n 2,3546 gold badges21 silver badges30 bronze badges1 Answer
Reset to default 13According to what is returned, you have all .video
elements in the root. So one way to get the number of .video
elements is to use .filter
method:
$(data).filter('.video').length;
本文标签: javascriptCounting HTML string elements using JqueryStack Overflow
版权声明:本文标题:javascript - Counting HTML string elements using Jquery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744245813a2597005.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论