With the following code I try to give an a element autofocus when the page is loaded.
<a href="/{{setting}}" id="next" class="button big active">Next vocabulary</a>
<script>
document.getElementbyId("next").focus();
</script>
Whilst this works fine with input fields it doesn't work with that a element. Can anybody explain me while?
Regards
The autofocus attribute is a boolean attribute. When present, it specifies that the element should automatically get focus when the page loads.
The autofocus attribute is a boolean attribute. When present, it specifies that an <input> element should automatically get focus when the page loads.
The autofocus property sets or returns whether a button should automatically get focus when the page loads, or not. This property reflects the HTML autofocus attribute. Note: The autofocus attribute is new for the <button> element in HTML5.
The problem is that you typed getElementById
wrong, it should be an uppercase 'B'.
<a href="/{{setting}}" id="next" class="button big active">Next vocabulary</a>
<script>
document.getElementById("next").focus();
</script>
This should now work!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With