Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery count elements with attribute

Tags:

jquery

count

Can I count the number of elements with a specific attribute?

For example all the images with the src attribute test.gif

like image 680
usertest Avatar asked Jan 08 '10 20:01

usertest


People also ask

How do I count the number of elements in jQuery?

To count all HTML elements, we use length property. The length property is used to count number of the elements of the jQuery object.

How do I count the number of characters in a string using jQuery?

We can find the length of the string by the jQuery . length property. The length property contains the number of elements in the jQuery object. Thus it can be used to get or find out the number of characters in a string.

What is jQuery length?

The length property in jQuery is used to count the number of elements in the jQuery object. The size() function also returns the number of elements in the jQuery object.

How do you find the length of a div?

You can simply use the jQuery . length property to find the number of elements in a DIV element or any other element.


1 Answers

Use the CSS attribute selectors to filter on the attribute

$("img[src='test.gif']").length;

the size() and length both returns the number of elements matched;

like image 145
chakrit Avatar answered Sep 21 '22 16:09

chakrit