How can I pass a variable to chrome.tabs.create?
I'm trying to set up event listeners to my anchors, but I'm creating them inside a for loop:
for (var i = 0; i < links.length; i++){
if(links[i][0] === text){
var a = document.createElement('a');
a.setAttribute('href', links[i][2]);
a.setAttribute('class','links_anchor');
a.innerHTML = links[i][1];
test = links[i][2];
a.addEventListener('click', function(){
chrome.tabs.create({
url: test,
active: false
});
});
document.getElementById('links_content').appendChild(a);
}
}
How can I pass a variable to the url parameter? What's happening now is that all the links have the same action. E.g. When I click any of them it opens the last URL from the array.