function createDropDown(){
const tree = document.createDocumentFragment();
const link = document.createElement('a');
for(let index = 0; index < urlList.length; index++){
link.appendChild(document.createTextNode(urlList[index]));
link.setAttribute("href", urlList[index])
link.setAttribute("id", "link "+index)
tree.appendChild(link);
document.getElementById("hyperlinks").appendChild(tree);
I am exploring JavaScript and HTML, trying to add multiple hyperlinks within a div named 'hyperlinks' by hard-coding it. The links are extracted from an array of URLs called 'urlList'.
However, the current issue I face is that only one hyperlink is displayed with all the URLs as text, and the URL attached to the link corresponds to the last URL in the urlList array. Any guidance on rectifying this is appreciated. Thank you.