P
P
Polina2020-04-23 20:36:25
React
Polina, 2020-04-23 20:36:25

How can e.target.selectionStart work and e.target.selectionEnd not work?

I don’t understand the magic of react at all, but with this snippet of code in the application, I correctly get startCursorPos, and don’t get endCursorPos at all. (endCursorPos remains zero) Why is this happening? how can this be fixed? And the documentation on the e.target.selectionEnd functions is not found on the site? (I have not found)

class TextArea{

constructor(props){
super(props);
this.state = {
startCursorPos: 0,
endCursorPos: 0
  }
}
getCursorPosition(e){
let start = e.target.selectionStart
let end = e.target.selectionEnd
this.setState({startCursorPos: start, startCursorPos: end}, () => this.saveChanges();})
} 

<div onSelect = {(e) => this.cursorPosition(e); e.preventDefault()}}>
    <Textarea/>
</div>
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question