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

316
Views
How to undo the formatting of a selected text?

I am trying to develop a simple WYSIWYG editor.

document.querySelector('button').addEventListener('click', () => {
  const range_of_selected_text = document.getSelection().getRangeAt(0).cloneRange();
  const TAG = document.createElement('strong');
  range_of_selected_text.surroundContents(TAG);
});
<button>B</button>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eius recusandae vero quasi laborum tempore quis cum eum! Quo temporibus deserunt consequatur laborum magnam, quidem magni, quia id, nisi consequuntur dolorem.</p>

In this case, surroundContents() allows displaying a selected text as bold. But how am I able to remove the <strong> tag if the text is already bold?

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!