I have some DOM inputs and I added some events to them, the inputs are like:
$("#hotel2city").keyup(function(){
getDestinations($("#hotel2city"));
});
$("#hotel2name").keyup(function(){
getHotels($("#hotel2city").val(),$("#hotel2name"));
});
which works, what I want to do is to not repeat every time the above code but to have a for loop that attach the events. So I wrote an IIFE:
var setControlls = function(){
for(var i=1; i<=5; i++){
$("#hotel" + i +"city").keyup(function(){
getDestinations($("#hotel"+i+"city"));
});
$("#hotel"+i+"name").keyup(function(){
getHotels($("#hotel"+i+"city").val(),$("#hotel"+i+"name"));
});
}
}();
but this does not work, any idea what I am doing wrong?