Jquery: event listener for array of elements

前端 未结 5 1270
被撕碎了的回忆
被撕碎了的回忆 2021-01-20 13:49

I am populating an array with elements using the .each() method and $(this) selector.

(function($){

    var elements = new Array()         


        
5条回答
  •  抹茶落季
    2021-01-20 14:04

    There is no need of an array, you can use the element selector along with has attribute selector to get all image elements with the given attribute, then use .click() to register the event handler

    $("img[attribute]").click(function(){
        //do your stuff
    })
    

提交回复
热议问题