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
Cast el
variable to HTMLInputElement
.
UPD:
const input : HTMLInputElement = <HTMLInputElement>el;
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