I am populating an array with elements using the .each() method and $(this) selector.
(function($){
var elements = new Array();
var index = 0;
$("img").each(function() {
if($(this).attr("attribute")){
$(this).attr("imageIndex", index);
elements[index] = $(this);
index++;
}
});
}(jQuery));
I would like to add an event listener to my code that is executed when any element in that array is clicked.
For example:
$(elements).click = function(){
console.log("success");
}
I suppose the onclick attribute could be changed as each image is looped through, but this seems somewhat inconcise. I would like to be certain that that is my last resort before I implement it.
$(selector)