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

88
Views
unable to target clicked element on successful Ajax return, when multiple elements have same name

i am trying to target 'clicked' element on successful Ajax return, when multiple elements have same class name.

  <td data-name='tom' class="status"><a href="">click</a></td>
  <td data-name='jack' class="status"><a href="">click</a></td>
  <td data-name='phil' class="status"><a href="">click</a></td>

I am able to target the clicked element using this.i.e:

  var name  =  $(this).attr("data-name");

I am however unclear how to target that same element on successful ajax return.

below is my ajax code example:

   $(".status").click(function(event){
            event.preventDefault();
            var name  =  $(this).attr("data-name");

            $.ajax({
                url: FORM_URL,
                type: "POST",
                data: {name:name},
                showLoader: true,
                cache: false,
                success: function(data){

                    var el = $(this)('.status');
                    el.empty();

                        el.append(
                            '<div class="status">' +
                            '<p>name changed</p>' +
                            '</div>'
                        )
                    }
                },
              
            });
            return false;
        });

The 'this' does not work on ajax success

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

0

keep element as a variable like so -

statusElement = document.querySelector('.status');

then add event listener and use the variable inside your function -

statusElement.addEventListener('click', function(event) {
    statusElement.empty();    
})
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!