codenoob
codenoob

Reputation: 539

Jquery how to use on() with array

$(document).on('change','#id1,#id2,#id3', function(){
       //run my code
    });

The above works

below does not

  var ids = ["#id1","#id2","#id3"];

  $(document).on('change', ids , function(){
           //run my code
        });

I also tried to ids.tostring() to see if changing array to string would work.

Upvotes: 0

Views: 65

Answers (1)

David
David

Reputation: 219016

Join the array into a string:

var ids = ["#id1","#id2","#id3"];

$(document).on('change', ids.join(','), function(){
    //run my code
});

Upvotes: 1

Related Questions