Using JS to redirect instead of anchor tag

function setCard(){
    const main = document.querySelector("main");

    for(let i = 0; i < projectData.length; i++){
        const card = makeCard(projectData[i].title);
        main.appendChild(card);

        card.addEventListener("click", () => {
            localStorage.setItem("id", projectData[i].id);            
        })
    }
}

The makeCard() basically returns a div thats wrapped in an anchor tag.
And I am adding click event listener to all the anchor tags cause i have to store the id in local storage of the card that has been clicked .

This works but idk why something feels sketchy about this to me. Idk what. Does this approach have any drawback?
Was this page helpful?