Mismatch of . append with length

Asked

Viewed 69 times

1

I have a script to generate images, and the images are generated with .append.

$(".fotos").append("<img src='" + size +"'/>");

The problem is that the append doesn’t generate the image in the source code, they are generated from the script itself, so I can’t count how many images there are.

I use this to count, and always returns 1, and appears 10 images.

alert($('img').parent('.fotos').length);

And like I said, only returns 1.

There’s another way to do it?

1 answer

3


Usa $(".fotos > img").length to select all images whose parent has class photos.

Your current code selects all images, then selects parent with class photos, and counts parents

Browser other questions tagged

You are not signed in. Login or sign up in order to post.