Let's start with the code:
function PopupDrop(n) { // function to trigger on click
for (var i=0; i<Popups.length; i++) {
if (($(Popups[i]['w']).css('display') != 'none') && (n != Popups[i]['w'])) {
$(Popups[i]['w']).stop(true,true).slideUp(150);
}
// Poping actual popup
if ($(n).css('display') == 'none') $(n).slideDown(150);
else $(n).slideUp(150);
}
var Popups = [ // Array of ID which we click, and ID's which we send to click trigger function
{c:'#Payment-Selection',w:'#Cards-Popup'},
{c:'#Drop-SY',w:'#Start-Years'},
{c:'#Drop-SM',w:'#Start-Months'}];
function ActivatePopups() { // Defining click events function
for (var i=0; i<Popups.length; i++) {
var Wt = Popups[i]['w'];
$(Popups[i]['c']).click(function() {
PopupDrop(Wt); console.log(Wt);
});
console.log('On click here: '+Popups[i]['c']+' do this:'+Popups[i]['w']); }
}
ActivatePopups();
Basicaly I'm doing custom select boxes, which must slideUp when others are slideddown. The problem here is that fuinction ActivatePopups console logs everything how it should be, but when I do click on different defined elements (eg. #Payment-Selection, #Drop-Sy...) the click does not trigger dropdown, and console.log shows same id on all clicks... If I define clicks without for loop, eg. $('#Payment-Selection').click(function() { PopupDrop('#Cards-Popup'); }); it works as charm... But as I have a lot of differend ID's I would like to shorten the code, with for loop.
Any ideas why is it happening?