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:
alert($('.capital_class').length);
Remember the event is called on a single element so this
is 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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With