How to make <button> inside <a> not follow the link src?
GavHern (64)

I'm making a friend's website and I have an <a> tag to link to a page about a game he's making. I also have a <button> inside that <a> tag to download the game. Since the button is inside the <a>, it follows the source of the link as well as downloading the file. How can I make the button do its own thing without following the <a> tag? Here's an image of what it looks like.

You are viewing a single comment. View All
JackLee7 (6)

@GavHern alright so lets say that your button has the id "download-button"

const button = document.getElementById("download-button");
button.addEventListener("click", e => {
    e.stopPropagation();
});