views:

41

answers:

2

There are many <label name="delQ" style="cursor:pointer">Remove</label> elements in a web page; the elements are dynamically created. How to determine how many "delQ" exist in the current web page?

$('[name="delQ"]').live('click', function() {
//Get the number of name="delQ" in the current web page.
});

How to do it in Jquery?

A: 
$('label[name="delQ"]').length;

length

Returns the number of elements in the jQuery object.

rahul
length is not a function. jQuery defines also .size() method that does the same.
Rafael
Corrected typo.
rahul
A: 

Just use the .length property

$('[name="delQ"]').length
Rafael
This selects all elements with name attribute set to "delQ" and not just label elements.
rahul
I used the same selector as the author of this question. You can of course change the selector to return only label elements with given name.
Rafael