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

139
Views
Get DOM on ajaxComplete

Is there any way to get updated DOM on ajaxComplete. I am able to get and modify responseJSON, responseText, etc. but I do not want to mess with text and searching for the right element.

$(document).ajaxComplete((event, xhr) => {
 let y = $('a')[0].getElementsByClassName('b')[0];
 y.onclick = (event2) => {
      console.log(event2);
  
      return false;
    };
}

When I am doing like above, it is not attaching the event to the new retrieved DOM element, but the old one I guess.

I want attach the event to new retrieved DOM element.

EDIT:
I have tried using this, event object and $ but all these variables are related to 'old' DOM

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It seems like you are using jQuery. jQuery has a sophisticated ajax helper.

 $.ajax({

   url     : "/api/get/user" // User Ajax endpoint,
   method  : "GET", // your Ajax method . post, get put 
   data : // data you want to sent to the backend

   }).fail(function() {

        // If Ajax failed then do this

  }).done(function(data) {

    // If Ajax success then do this

  });

In the user case what I do, I will call my functions ( in your case ajaxComplete maybe ) inside .done()

and I will replace

let y = $('a')[0].getElementsByClassName('b')[0];

by

let y = $('a').find('b'); // or dynamic class or id

code pen : https://codepen.io/umanda/pen/abwboqp

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