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

133
Vistas
How to strip html tags out of selection

I want to strip html tags out of a selected text which is inside a content editable div. Lets say selected text is something like this:

<div contenteditable="true">
  <span style="color:red">some text</span>
</div>

So I tried this:

window.getSelection().anchorNode.parentNode.replace(/<\/?[^>]+>/gi, '');

but I get an error that says replace is not a function. I tried also this below:

window.getSelection().anchorNode.parentNode.remove();

but this will remove also the text. Whats the deal here?

Thank you.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Like this

const editable = document.querySelector('div');
const button = document.querySelector('button');

button.addEventListener('click', () => {
  alert(editable.innerText);
});
   <div contenteditable="true">
    <span style="color:red">some text</span>
   </div>
   
   <button>Show me the text</button>

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