Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

220
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda