3

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.

1 Answer 1

13

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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.