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

265
Vistas
"Uncaught TypeError: Cannot read property 'createDocumentFragment' of undefined" issue
function addEditButton() {
    $(".editButton").remove();
    $(".transaction.highlight").removeClass('highlight');
    $(this).addClass('highlight');
    $(this).append("<input type='button' class='editButton' value='edit' />")
}

$("body").on('click', '.transaction', addEditButton());

I am getting an error message of "Uncaught TypeError: Cannot read property 'createDocumentFragment' of undefined" when using the above code.

I've tried searching through some of the same questions that have been posted about this and I now assume the error is because of the way I am using "this" but I am not sure how to fix the problem.

The code works just fine if I put all the code inside the $("body").on call, but not when I use the external addEditButton() function. Can anyone help please?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Don't call the function when you bind it, just pass it as reference.

$("body").on('click', '.transaction', addEditButton);
over 4 years ago · Santiago Trujillo Denunciar

0

You're assigning the result returned by your addEditButton function, instead of a reference to the function itself. Drop the parentheses and it should work:

$("body").on('click', '.transaction', addEditButton);
over 4 years ago · Santiago Trujillo 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