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

209
Views
JavaScript - Contenteditable bold option without execCommand

I want to create a simple WYSIWYG editor with contenteditable and a bold option. This used to be really easy to achieve using execCommand as can be seen here.

Unfortunately execCommand is now deprecated.

My approach to achieve this without execCommand would be the following:

  1. Get selection with window.getSelection()
  2. Convert the selection to a text node on which I can set innerHTML and make sure it is a descendant of the contenteditable div
  3. Do a simple transform of the innerHTML (e.g. node.innerHTML = '<b>' + node.innerHTML + '</b>')

However, I am not sure how to achieve the second part. window.getSelection().anchorNode returns the correct node, but it won't let me set innerHTML or innerText on it.

Is this even possible? Thanks in advance!

about 4 years ago · Juan Pablo Isaza
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!