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

254
Views
"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 answers
Answer question

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 Report

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 Report
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!