My goal was to include the id value of the active element in a URL and then redirect to that URL with a button click.
HTML
<div class="icon" tabindex="0" id="company">
<img src="company.png">
</div>
<button type="submit" onclick="myFunction()">jump</button>
Javascript
function myFunction(){
var x = document.activeElement.id;
location.href = "apps-online.html?page=" + x;
}
When clicking the button, my expectation was to be redirected to:
"apps-online.html?page=company"
However, the url ended up being:
"apps-online.html?page="
I'm puzzled as to why the value of x wasn't added to the url.
Hello everyone. I have now realized why this issue occurred. Each time the button is clicked, it becomes the last active element.
Is there a way to solve this and achieve my desired result?