I'm implementing a way to track clicks in a tabbed content section.
When I click any tab, the parameter is passing as clicked=tab4. It should be clicked=tab(value of 0-3). It looks like it's returning the length of the array? How can I make the event listener function keep the index value of the array.
Example: when I click tab1, the variable "i" in the event listener should be 0.
Here is my code. It works except for this one part, and I can't figure out why.
function clickTrack(){
var tabs = ['tab1', 'tab2', 'tab3', 'tab4'];
for(i = 0; i < tabs.length; i++) {
document.getElementById(tabs[i]).addEventListener("click", function(){
trackingFunction('param1','clicked=tab'+ i);
alert(i);
});
}
}