How to index an array on a set of elements?

advertisements

I can index a group of elements, or go .length, but I don't know how to bind them to an array.

I want to make the array by locating all of a set of elements and then alter some of the properties, so, say, make an array of "p" elements and then on finding it apply a function.

It's hard to say what I mean, so, when I click the child of the container div it returns it's position, but how can I use that number to grab the element of the div

$(function(){
    var arr = ["div.hex1", "div.hex2", "div.hex3",];
    $("div.hexagons").children().click(function(){
        var find = $(this).index();
        $(find)[arr].css({'background':'black'});
    });
});


"I want to make the array by locating all of a set of elements, so, say, make an array of "p" elements and then on finding it apply a function."

In the way jQuery is designed, the most convenient would be to use

myArray = $("p");

And to modify the elements, use, i.e. :

myArray.find( ".myClass").css( "background-color", "red" );