How do I return the index of only the button that is clicked?
Here's the code that got me worried:
window.onload = function(){
var    description = document.getElementsByClassName('description'),
        buttons = document.getElementsByClassName('button');
var currD = 0; // this var stands for the current description that should be shown
var show = function(){
    for( var i = 0; i < description.length; i++ ){
        if( i !== currD ){
            description[i].style.display='none';
        }
        else if( i === currD ){
            description[i].style.display='block';   
        }
    }
};
  for (var i = 0; i < buttons.length; i++){
    buttons[i].addEventListener('click', function(){
        currD = i;
        console.log(i);
    });
}
    window.setInterval(show,300);
};
Every time I click the button the for loop return the last element.
Since I didn't have many buttons on this page I went for the unproficient old way which is:
window.onload = function(){
var description = document.getElementsByClassName('description'),
    buttons = document.getElementsByClassName('button');
    var currD = 0; // this var stands for the current description that should be shown
    var show = function(){
        for( var i = 0; i < description.length; i++ ){
            if( i !== currD ){
                description[i].style.display='none';
            }
            else if( i === currD ){
                description[i].style.display='block';   
            }
        }
    };
buttons[0].addEventListener('click', function(){
    currD = 0;
});
buttons[1].addEventListener('click', function(){
    currD = 1;
});
buttons[2].addEventListener('click', function(){
    currD = 2;
});
        window.setInterval(show,300);
    };
This works but if I want to add more buttons it'd be a loss of time setting all the event listeners.
 
     
    