this image is my app post detail page
this app is service about booksaling so user can post about booksale
the feature is
userAcreate a post (he want sale book1, book2, book3)- if book2 was sold out
userAshould clicksold out button - when
sold out buttonclicked,sold outwill convertedclick cancelandstrikeline will added book2 (likebook2(2222원))
so i decide using js+ jquery
here's my js code
(function(){
$(document).ready(function(){
//$book_list_num is received number of books
//book1, book2, book3//$book_list_num = 3
$book_list_num = $("div").data("listNum");
console.log($book_list_num);
var $cancel_button = []
for(i=1; i<= parseInt($book_list_num); i++){
//$cancel_button[0]=#btn1,
//$cancel_button[1]=#btn2,
//$cancel_button[2]=#btn3
$cancel_button[$cancel_button.length] = $("#btn"+i);
$cancel_button[i].on('click', function(event){
//test alert
alert(i)
});
};
});
})();
but web browser console show error
cancelbutton.js:14 Uncaught TypeError: Cannot read property 'on' of undefined
I can not understand why js can't read onmethod
please somebody help me

$cancel_buttonarray are already jQuery objects. But OP hasn't allowed for array indices being zero-based.