Why button.click() is not working in my script?

I have a script in JavaScript that in a part of the code create a ‘virtual button’ and press it automatically.

This button is not in the HTML page and is only used to store a link that at a certain point of the script must be clicked. Here’s the code:

var virtualButton = document.createElement("button");
var linkText = document.createTextNode("assign to relevant user");
virtualButton.appendChild(linkText);
virtualButton.title = "assign to relevant user";
virtualButton.href = link;
document.body.appendChild(virtualButton);

virtualButton.click();

Everything seems fine to me, still the code does not actually click the button.

Am I missing something here?