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;
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744245813a4564921.html
评论列表(0条)