I have an array geneList where loop is applied over it. So, that href will change as loop iterate where hangoutButton will automatically click and redirect to the given url. Sounds Simple
Problem:- Loop is iterating you can see into console that your is iterating but href value is not iterating. It Like href is been stuck on first index only. When page is redirect you will see array of first index into key on every iteration. You can observe key is iterating in console.
Can anyone please help
Thank you in advance........
var geneList= ["123", "456", "678","2345"];
geneList.forEach(function(key){
// GSEA Redirect Button
var sample= document.createElement('a');
sample.href = "forEdit3.php?randNum=" + key;
sample.target = "_blank";
sample.style.display = "none";
var samplebutton = document.createElement('button');
samplebutton .innerHTML = "BarPlot";
samplebutton .className = "btn";
samplebutton .id = "autoClickbarPlot";
forPlot.appendChild(sample);
sample.appendChild(samplebutton );
var hangoutButton = document.getElementById("autoClickbarPlot");
hangoutButton.click();
console.log(key);
});
.click()method does not work like that, it's invoked immediately it doesn't wait for a user to trigger click event it triggers without user interaction.[.click()].forEach()which means when each of those links and buttons are being created a click event is fired. Of course this is only true if the code actually worked (which as it looks ATM will not)