0

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.

1 Answer 1

4

You can use wild card, starts with selector.

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

Live Demo

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

arr.each(function(){
    alert($(this).text());
});​
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, I want to access them later to compare them with other functions. is it possible to do it??
I have added a demo which access each of them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.