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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:58:25+00:00 2026-05-29T23:58:25+00:00

I have a feed with comments and want to allow users to delete a

  • 0

I have a feed with comments and want to allow users to delete a comment. The code below allows users to click on an image and a dialog box appears that alerts users of the deletion.

Right now, this applies to every comment on the page, so that clicking the delete button once opens up multiple dialogs (as many dialogs as there are comments).

How can I alter the code below so that when the selector is clicked, only the dialog box for that comment appears?

$('span.delete_comment_button img').click(function() { 
        $('.delete_comment_dialog').dialog('open'); 
        return false; 
});
  • 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-05-29T23:58:26+00:00Added an answer on May 29, 2026 at 11:58 pm

    First of all, you should not have multiple #delete_comment_dialog elements on the page so we’ll change that to .delete_comment_dialog. Then you can add a class to the comment as a whole, use closest to go up to the top level comment wrapper, and find to come back down to the dialog. The HTML would look something like this:

    <div class="comment">
        blah blah blah blah
        <span class="delete_comment_button">delete</span>
        <div class="delete_comment_dialog">first dialog</div>
    </div>
    <div class="comment">
        blah blah blah blah
        <span class="delete_comment_button">delete</span>
        <div class="delete_comment_dialog">second dialog</div>
    </div>​
    

    And your jQuery like this:

    $('span.delete_comment_button').click(function() {
        $(this).closest('.comment')
               .find('.delete_comment_dialog')
               .dialog('open');
        return false; 
    });​
    

    Demo: http://jsfiddle.net/ambiguous/VePZp/

    Alternatively, use a single dialog with an id attribute, add ids to your comment <div>s, and pass the id of the comment to delete through a data attribute or similar. For example:

    <div id="cmt1" class="comment">
        blah blah blah blah
        <span class="delete_comment_button">delete</span>
    </div>
    <div id="cmt2" class="comment">
        blah blah blah blah
        <span class="delete_comment_button">delete</span>
    </div>
    <div id="delete_comment_dialog">the only dialog</div>
    

    And:

    $('#delete_comment_dialog').dialog({
        autoOpen: false,
        close: function() {
            // 'close' handler just for demonstration purposes.
            alert($('#delete_comment_dialog').data('kill-this'));
        }
    });
    $('span.delete_comment_button').click(function() {
        var $cmt = $(this).closest('.comment');
        $('#delete_comment_dialog').data('kill-this', $cmt[0].id);
        $('#delete_comment_dialog').dialog('open');
        return false; 
    });​
    

    Demo: http://jsfiddle.net/ambiguous/M4QM6/​

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

Sidebar

Related Questions

I have the following Javascript code, where feed is a valid url to an
We have a feed process which runs every day of the year. As part
The thing I have a web app (asp.net) which needs to have a feed.
I recall I have read about a parser which you just have to feed
I have an XML feed (which I don't control) and I am trying to
I have a calendar feed (.ics) available from my application, but it's quite large
I have a JSON feed (which I don't directly control, I have to ask
I have a news feed where items in the feed are created from JSON
I have a RSS feed i need to display in a table (its clothes
Basically I have an xml feed from an offsite server. The xml feed has

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.