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

  • Home
  • SEARCH
  • 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 8133191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:32:01+00:00 2026-06-06T09:32:01+00:00

I have question i.e how can i select a previous div CODE:- if($i >

  • 0

I have question i.e how can i select a previous div
CODE:-

if($i > $start_from){
                echo "<div id=\"blog$i\"><h1 style=\"padding-top:30px; font-size:14px;\" id=\"shareContent\"><a target=\"_blank\" href=\"$url\">$title</a><br /></h1>
                $desc
                <br />
                <p><em>hahaquotes, DATED: $date, URL: <a target=\"_blank\" href=\"$url\">$url</a></em></p>
                <div class=\"applyLink\" style=\"width:720px; padding-right:12px; margin-top:20px;\">
                <p><a target=\"_blank\" href=\"$url\">READ</a><span style=\"float:right; cursor:pointer;\"><a class=\"delete\">DELETE</a></span></p>
                </div></div>";
                if($i == $start_from + 4) break; 
                }
                }

This is my code When i click on DELETE the whole div should be deleted the id for div is dynamically created how can i achive this using jquery. Please Help me Thank you in advance

  • 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-06T09:32:04+00:00Added an answer on June 6, 2026 at 9:32 am

    Attach a click handler to the anchor using the delete class as a selector. Within the handler this will refer to the clicked element, and from there you can traverse to the thing you want to delete without needing to know its id:

    $("a.delete").click(function() {
        $(this).closest("div").closest("div").remove();
    });
    

    The .closest() method traverses up through the DOM to find the closest ancestor matching the supplied selector. In your particular html structure the div you are looking for is the second-closest, so I’ve simply chained two invocations of .closest() together.

    You can simplify this if you modify your html to give the div you want to remove a particular class, say “entry”, because then you can traverse up to it with a single call to .closest() as follows:

    echo "<div id=\"blog$i\" class=\"entry\">(etc.)"
    
    $("a.delete").click(function() {
        $(this).closest("div.entry").remove();
    });
    

    If you have several of these structures then each “delete” link would remove only the div that it belongs to.

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

Sidebar

Related Questions

Following on from a previous question, I have the following code: var results =
I have a question that can I use AS400ConnectionPool in Spring if then pls
Reading this article http://support.microsoft.com/kb/813878 I have a question: Where can I get ipseccmd.exe for
I have a smple Question: How can I access to a class and its
I have another question and I can't seem to find anything on Google. What
I have question regarding the SQLAlchemy. How can I add into my mapped class
I have not been able to find any definitive answers to this question: Can
I know this question can be answered by searching in google. But I have
I have a quick question that I can't seem to find online. I am
I have following question on adobe omniture How we can register an iPhone app

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.