Oto Shavadze
Oto Shavadze

Reputation: 42853

How can I utilize selectionStart?

As I understood, selectionStart must return start position from selected text in input text or textarea elements

I have this js code

 $("#inpt").on("mouseup" , function () {
    alert( $("#inpt").selectionStart);
});

and html

<input id="inpt" type="text" value="bla bla bla" />

When I select some part in text "bla bla bla" the result is "undefined". Yell please, where did I go wrong ?

Upvotes: 1

Views: 5897

Answers (1)

xdazz
xdazz

Reputation: 160943

Try this.selectionStart, it's not the property of jQuery object, but the HTMLInputElement's property.

$("#inpt").on("mouseup" , function () {
    console.log(this.selectionStart);
});

Upvotes: 3

Related Questions