Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The property doesn't exists in value type of HTMLElement

In typescript i need to implement specific caretPosition of an input element.But when i try to implement it shows createTextRange type does not exists in type HTMLElement. any one have solution for this?? Thanks in advance.

following is my code

private setCaretPosition() {
    var el = document.getElementById("ticketInfo");
    if (el !== null) {
        if (el.createTextRange) {
            var range = el.createTextRange();
            range.move('character', el.value.length);
            range.select();
            return true;
        }
        else {
            if (el.selectionStart || el.selectionStart === 0) {
                el.focus();
                el.setSelectionRange(length, length);
                return true;
            }
            else { // fail city, fortunately this never happens (as far as I've tested) :)
                el.focus();
                return false;
            }
        }
    }
}

it is showing createTextRange() undefined

like image 569
Jaleswar Putel Avatar asked Dec 08 '22 00:12

Jaleswar Putel


1 Answers

Cast el variable to HTMLInputElement.

UPD:

const input : HTMLInputElement = <HTMLInputElement>el;
like image 173
sinedsem Avatar answered Dec 14 '22 22:12

sinedsem