How do I count dynamically generate elements with the same class in jquery?
I found a similar question, but unfortunately it didn’t work.
jQuery counting elements by class; what is the best way to implement this?
I did something like this which I based from the answers:
$('.capital_class').live('blur', function(){
alert($(this).length);
});
The elements with a class of capital_class are dynamically generated. But I always get the length of 1, whenever I blur. How do I get this correctly?
Change the alert to this:
Remember the event is called on a single element so
thisis just a single element — you have to have jQuery query the dom after the event happens. (The first query just sets up the live handling to create the event handlers.)