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 7859737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:01:14+00:00 2026-06-02T22:01:14+00:00

I have a link inside a <li> element and want the <li> element to

  • 0

I have a link inside a <li> element and want the <li> element to be removed when the link is clicked. Here is my code:

<li id='i80'>
 <div class='singleitem'>
  <img src='/css/images/image.png' width='30' height='30' />
  <div id='listtext'><h1>Title</h1></div>
  <a class='delete' id='80' href='#'></a>
  <div id='helper'></div>
 </div>
</li>

And my Jquery code:

$(".delete").click(function(e){
 var del_id = $(this).attr('id');
 e.preventDefault();
 $.post("/add/delete.php", { iid: del_id } ,function(data){
  if(data.status == 'deleted');
   {
     $(this).closest("li").remove();
   }
 });
});

The ajax is working fine and the ‘deleted’ status is being sent back correctly, however, that one line that involves removing the parent li just doesn’t work. Any ideas? Thanks.

EDIT:

I’ve noticed that new list items I’ve added dynamically to my existing ul don’t work here. Is that because this just loads when the page loads initially and then won’t work with with dynamically updated content?

  • 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-02T22:01:15+00:00Added an answer on June 2, 2026 at 10:01 pm

    $(this) object within ajax block isn’t $(“.delete”) object. You will need to do something like this:

    $(".delete").click(function(e){
     var $del_button = $(this);
     var del_id = $(this).attr('id');
     e.preventDefault();
     $.post("/add/delete.php", { iid: del_id } ,function(data){
      if(data.status == 'deleted');
       {
         $del_button.closest("li").remove();
       }
     });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: <h1><a href=# class=link>Click here</a></h1> <div class=acitem></div> <div class=acitem2></div> <script>
I want to have the link inside the DIV instead before. I want to
I have a link button inside UpdatePanel in a div popup. On Button_Click, I
I have created a clickable div element that has a few links inside it.
I have a div element which I append to body element $('<div class=tooltip></div>').appendTo('body'); and
I have a page with lots of tables, each with a link inside. I
I have link that calls a function when clicked: <a href=javascript:spawnMenu(this); id=link1>Test1</a> To make
I have link for example domain.com/de/controler/action?param=value and I want make actionlink to keep same
I have a link, with which i want use plus, which will change color
I have a div element on my web page with ID map with a

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.