sim fiza
sim fiza

Reputation: 21

Check number of elements added to <div> dynamically

I am dynamically adding images inside a div using jQuery.

I have put an alert() after an element has been added successfully. Is there any way in jQuery to check if a list of elements has been added into a div tag?

Upvotes: 0

Views: 86

Answers (2)

Adil Shaikh
Adil Shaikh

Reputation: 44740

Try this -

$('div img').length;

Upvotes: 3

PSR
PSR

Reputation: 40338

Try to put global variable then increment this value by one in that method.Finally you will get count.There is no need of jQuery here

$(".selector").each(function(){
    var images = $(this).find("img");

});

Upvotes: 0

Related Questions