Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

237
Views
How to put/paste the content where cursor is there in content editable div

I am a newbie on react. I have a content editable div. What I want is Make a button, on button click -> "HEY" word will be added. Let's say my content length is 100, and I have clicked on initial 5 character and giving the space and click my paste button. So the "HEY" content will be append in that position.

My code:

renderValue = () => {
 var textNode = document.createTextNode("HEY");
      let p1 = document.getElementById('work').focus();
      p1.appendChild(textNode)
}

render(){
<button onClick={() => this.renderValue()}>Paste</button>
<div id="work" onClick={(e)=>e.stopPropagation()}  
contentEditable 
onInput={this.emitChange}
dangerouslySetInnerHTML={{__html: this.props.html}}
>
</div>
}

I have tried to append the text but not getting luck.

Anny help is really appreciated. Thanks in advance.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use document.execCommand() with insertText command. Like

document.execCommand("insertText", false, "HEY!!")
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!