Autofocus attribute with <input> element?

Hi folks :slight_smile:

i was wondering whether it is possible to use the autofocus attribute with an <input> or <textarea> element. If tried autofocus="autofocus" or just autofocus, but is does not seem to work.

Is there a way?

Cheers

Maybe something like this

<input type="text" id="custom_id" >

<script>
var CustomTypebox = document.getElementById("custom_id");
if (CustomTypebox) {
CustomTypebox.focus();
}
</script>

or:

<script>
var firstInput = document.querySelector("input[type='text']");
if (firstInput) {
firstInput.focus();
}
</script>
1 Like

Thanks for your reply :slight_smile:

It works great on Anki Desktop as well as on Ankiweb.net

For Some reason, it does not seem to work for me on Ankidroid. Do you know, why that might be the case?

1 Like

To be honest, I’m not quite sure. I lack familiarity with the inner workings of AnkiDroid and don’t even know how to utilize inspection tools for a more in-depth investigation.

Considering that even regular text input boxes don’t receive autofocus on AnkiDroid, my best guess would be that there’s possibly some code deliberately preventing this behavior.

Here are a couple of somewhat related topics I just found online: Ankidroid text input field does not have focus, "Type in the answer" auto focus for answer field · Issue #4699 · ankidroid/Anki-Android · GitHub

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.