Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8947203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:41:52+00:00 2026-06-15T12:41:52+00:00

I have an AJAX method that deletes a row from a database from a

  • 0

I have an AJAX method that deletes a row from a database from a list of results from the database. Once the row has been successfully deleted, I want jQuery to fade out that row from the page.

After clicking on the delete button, the row is successfully deleted from the database, but the list item that is the parent of the button that was clicked does not fade out when searching for it using closest().

Here is my DOM:

<ul>
    <li>
        <div class="two columns alpha">
        </div>
        <div class="ten columns">
            <ul>
                <li><p></p></li>
                <li><p></p></li>
            </ul>
        </div>
        <div class="admin_buttons">
            <div class="two columns">
                <button type="submit" class="admin_button edit_event">Edit</button>
            </div>
            <div class="two columns omega">
                <button type="submit" value="5" class="admin_button delete_event">Delete</button>
            </div>
        </div>
    </li>
</ul>

Here is the jQuery:

$(document).on('click', '.delete_event', function() {
    $.ajax({
        type: 'POST',
        url: 'php/deleteEvent.php',
        cache: false,
        data: {
            id: $(this).val()
        },
        success: function(data) {
            if(data === 'Error') {
                alert('Error: event not deleted.');
            }
            else
            {
                $(this).closest("li").fadeOut('slow');
            }
        }
    });

});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:41:53+00:00Added an answer on June 15, 2026 at 12:41 pm

    The reason it isn’t working as you expect is because the this you get inside the success callback is not the this you have inside the click handler.

    .ajax() has a context option for setting what gets passed to the success callback as this. You can use that:

    $.ajax({
        type: 'POST',
        ...
        context: $(this), // set what 'this' will be inside the callback.
        ...
        success: function(data) {
            ...
            // this refers to what we set for context
            this.closest("li").fadeOut('slow'); 
            ...
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a AJAX post method that gets xml data from server. But when
I have a method that calls another method (on ajax load, but that's irrelevant
I am simply learing Ajax with jQuery and have a simple page method that
My table is being populated using ajax from a mysql database. I have a
I have a usercontrol that is rendering a list of items. Each row contains
I have a web application that uses AJAX to grab JSON data from the
With jQuery ajax method I have a request on some file, which returns data
I have made a form validation using ajax post method. But i got the
I have this AJAX code, but it doesn't seem to throw the 'alert' method.
I have a method I want to call using AJAX in rails but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.