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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:15:23+00:00 2026-06-15T17:15:23+00:00

i am trying to delete the closest li element. the thing is that there

  • 0

i am trying to delete the closest li element. the thing is that there is loop which is creating the li elements with same id. this is fine so far, but there is another loop which is doing the same job. in each li element, there is a js delete function which takes the id of each each li. but now, if i click the li element of the second loop, it is deleting the first li in the first loop. my js code for the first loop is this:

function del_contact_a(cid){
        $.ajax({
            url: "/del_contact_a/",
            data: {id:cid},
            type: "POST",
        }).success(function(){
            $('#'+cid).closest('li').remove();
        })
}

js code for the second loop is this:

function del_contact_ver(cid){
        $.ajax({
            url: "/del_contact_ver/",
            data: {id:cid},
            type: "POST",
        }).success(function(){
            $('#'+cid).closest('li').remove();
        })
}

my both loops are these:

{% if contact_a %}
{% for ac in contact_a %}
<li id="{{ac.id}}"> <a> {{ac.name}} {{ac.nachname}}</a> <a onclick="del_contact_a({{ac.id}})"> <img src="{{STATIC_URL}}images/erase.png" /> </a>  </li>
{% endfor %}
{% endif %}

..

{% if contact_a %}
{% for ac in contact_a %}
<li id="{{ac.id}}"> <a> {{ac.name}} {{ac.nachname}}</a> <a onclick="del_contact_ver({{ac.id}})"> <img src="{{STATIC_URL}}images/erase.png" /> </a>  </li>
{% endfor %}
{% endif %}

can someone give me clue please? thanks alot

  • 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-15T17:15:24+00:00Added an answer on June 15, 2026 at 5:15 pm

    You have the same id on the 2 loops for your li.
    You should use a prefixe on each one, depending on your loops.

    The first one :

    <li id="a-{{ac.id}}">
    

    The second one :

    <li id="ver-{{ac.id}}">
    

    And change in you “” accordingly

    An id, must be unique as its name suppose it 😛

    Additionaly, I don’t understand why you are using the closest method ?

    $('#'+cid).remove();
    

    should be enough.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to delete ListView items that are checked. It works if there is
I am trying to delete a cookie with this function , but it doesnt
I am trying to transform my Outlook2003 into the closest thing to gmail. I
I'm trying to add a button that contains the .closest & .remove into an
I'm trying to add the functionality to this dynamic order form that will auto
I'm trying to create a Macro in Excel 2007 that will delete itself when
I'm trying to figure out how to delete an element (and its children) from
I'm currently trying to select the previous closest list element within an <ul> My
I am trying to delete a hidden element. I have tried the following codes
Just trying to delete all the documents, and did this: http://localhost:8983/solr/update?stream.body=%3Cdelete%3E%3Cquery%3E*:*%3C/query%3E%3C/delete%3E then committed: http://localhost:8983/solr/update?stream.body=%3Ccommit/%3E

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.