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

215
Views
How can i remove inline styles when copied text nodes from div which has contenteditable attribute?

While I write code a copy function for text rich editor, got a problem. When I trying to get text which stored from div which has contenteditable attribute into clipboard, it wrapped by many inline styles. I don't want to wrapped it inline styles, because body size will be increase.

  1. define div tag and paste event
    <div contenteditable id="test" style="min-width:600px; min-height: 800px;"/>
    
    document.getElementById("test").addEventListener("paste", (e)=>{
        e.preventDefault();
        console.log(e.clipboardData.getData("text/html")); 
    })
  1. write some text into div tag.
  2. select range substrings and copy.
  3. it will be printed like under.
<meta charset='utf-8'><span style="color: rgb(0, 0, 0); font-family: &quot;Apple SD Gothic Neo&quot;; font-size: medium; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;">sdasdasdas</span>

How can I get a copied text that only has exactly in line styles what i intend like below?

<span>sdasdasdas</span> or <span style="color: rgb(0, 0, 0);">sdasdasdas</span>

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!