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

130
Vistas
Remove certain text before pasting it

I have a paste event where i get certain plain text, so i want to remove a text from the copied text and paste it.

text copied in Clipboard

<p style="font:10pt Times New Roman, Times;" pid="123">
    This Amendment contains only the Cover Page, this Explanatory Note.
</p>

So i want to remove is pid="123" , how can i possibly be able to do it?

    myTextArea.addEventListener('paste', (e) => {
     let html = e.clipboardData.getData('text/plain');
                
     console.log('i pasted', html);
    });
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can use regex pattern and replace method to get the correct string. Here is the code:

myTextArea.addEventListener('paste', (e) => {
 let html = e.clipboardData.getData('text/plain');
 let transformed_html = html.replace(/pid=\"[0-9]*\"/, "");
 console.log('i pasted', transformed_html);
 
 const selection = window.getSelection();
 if (!selection.rangeCount) return false;
 selection.deleteFromDocument();
 selection.getRangeAt(0).insertNode(document.createTextNode(transformed_html));

 event.preventDefault();
});
about 4 years ago · Juan Pablo Isaza Denunciar

0

You need to create an element first in order to change attributes.

otherwise you'll have to do string manipulation, either using loops or Regex.

let htmlAsText = `<p style="font:10pt Times New Roman, Times" pid="123">
    This Amendment contains only the Cover Page, this Explanatory Note.
</p>`;

let div = document.createElement("div");
div.innerHTML = htmlAsText;
div.querySelector("p").removeAttribute("pid");

document.querySelector("body").appendChild(div)

createElement() removeAttribute()

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