I'am trying to add some js to my page, I create from it's a button and the aim of creating it is to redirect to another page but it is not working. Can you help me to solve it?
The situation is: the button is visible on my front-end (.jsp in Java EE), but there is no redirect. No matter what I write in URL simply no action is being made form click.
buttonAbort.innerHTML = 'Anuluj';
buttonAbort.style.cssFloat = 'left';
buttonAbort.style.width = '70px';
buttonAbort.style.height = '30px';
buttonAbort.style.backgroundColor = 'red';
button.setAttribute("id","buttonAbort");
let buttonAbortById = document.getElementById("buttonAbort");
buttonAbortById.onclick = function href() {
location.href="/projekt/edytujStatus";
}
You most likely have a mistake in your code.
You probably want to do
buttonAbort.setAttribute("id","buttonAbort");
instead of
button.setAttribute("id","buttonAbort");