user1847051
user1847051

Reputation:

Html elements into an array with jQuery

I have unlimited number of

<div class="item-1">text</div>
<div class="item-2">text</div>
<div class="item-3">text</div>
<div class="item-4">text</div>
<div class="item-5">text</div>
...

I want to search for all the available div and store them in an array with jQuery.

Upvotes: 0

Views: 52

Answers (1)

Adil
Adil

Reputation: 148110

You can use wild card, starts with selector.

arr = $('[class^=item-]');

Live Demo

arr = $('[class^=item-]');

arr.each(function(){
    alert($(this).text());
});​

Upvotes: 4

Related Questions