ursus contionabundo: HTML Input (Autofocus) mit value. Focus an das ENDE des Input Feldes

Beitrag lesen

Hallo,

danke für den Hinweis, leider ebenfalls ohne Änderung:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js" />

wird nicht mehr gebraucht. Ist "Vanilla-JS"

//usage
//moveCursorToEnd($('input'));

function moveCursorToEnd(el) {
    if (typeof el.selectionStart == "number") {
        el.selectionStart = el.selectionEnd = el.value.length;
    } else if (typeof el.createTextRange != "undefined") {
        el.focus();
        var range = el.createTextRange();
        range.collapse(false);
        range.select();
    }
}

Dein DOM-Element hat die ID "search":

<input type="search" class="form-control form-control-lg" name="s" value="Katastrophe" id="search" />

Also musst Du zu einem geeignetem Zeitpunkt (onload?) folgendes feuern:

var el = document.getElementById( "search" );
moveCursorToEnd( el );