Counting HTML string elements using Jquery

ajax, html, javascript, jquery

Solution

According 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;

Problem

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.

Original source