Caret will be placed at the end when textbox automatically gets focus

Published: | Categories: DOM

Description

Previously, when an <input> or <textarea> element received a focus with the focus method, a caret was initially placed at the beginning of the text, and therefore, both the selectionStart and selectionEnd properties on the form control would always be 0.

Firefox 51 has changed the behaviour to follow the HTML spec, so that a caret will be placed at the end of the text, and these properties will be the same value as the text length. The setSelectionRange method can be used to specify the selection range if needed.

References