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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:41:21+00:00 2026-06-13T10:41:21+00:00

How do I undelegate the #submit click event? $(document).ready(function(){ $(.agent img).click(function(){ $(.agent-form).remove(); var agentid

  • 0

How do I undelegate the #submit click event?

$(document).ready(function(){
            $(".agent img").click(function(){
                $(".agent-form").remove();
                var agentid = $(this).attr("alt"),
                    response = "<form method='post' action='' class='agent-form'><textarea placeholder='Your Comment' name='comment' id='comment'></textarea><input type='button' value='submit' id='submit' /></form>";
                $(response).hide().appendTo(this.parentNode).fadeIn();
                $(".agent").delegate("#submit","click",function(){
                    var message = $("#comment").val();
                    message = escape(message);
                    var dataString = "agent="+agentid+"&message="+message;
                    $.ajax({
                        type: "POST",
                        url: "includes/newcomment.asp",
                        data: dataString,
                        success: function(){
                            console.log(dataString);
                        }
                    });
                });
            });
        });

I want to undelegate all #submit click events that were created on previous .agent img clicks. The problem is that if the user clicks on an agent img then decides to click on another img the ajax submits to different datastrings.

  • 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-13T10:41:22+00:00Added an answer on June 13, 2026 at 10:41 am

    Per the jQuery doc for .delegate(), you can use .undelegate() to remove an event handlers.

    You don’t show us your HTML, but this sounds more like you should just have one delegated event handler that is always there rather than creating one, removing one, creating another, etc… You can store the agentid in the form element when you create it and then retrieve it upon the submit handler like this.

     $(document).ready(function(){
    
            $(document).delegate("#submit", "click", function() {
                var message = $("#comment").val();
                message = escape(message);
                // get agentid for this form
                var agentid = $(this).closest("form").data("agentid");
                var dataString = "agent="+agentid+"&message="+message;
                $.ajax({
                    type: "POST",
                    url: "includes/newcomment.asp",
                    data: dataString,
                    success: function(){
                        console.log(dataString);
                    }
                });
            });
    
            $(".agent img").click(function(){
                $(".agent-form").remove();
                var agentid = $(this).attr("alt"),
                // build form HTML (embed agentid into it for later retrieval)
                var response = "<form method='post' action='' class='agent-form' data-agentid='" + agendid + "'><textarea placeholder='Your Comment' name='comment' id='comment'></textarea><input type='button' value='submit' id='submit' /></form>";
                $(response).hide().appendTo(this.parentNode).fadeIn();
            });
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code which is using delegate method of jquery. e.g.: $(document).delegate('.forImg','dblclick',function(event){. .
How to undelegate this, and how to re-delegate (on/off)... Without affect the other event
I want to prevent multiple submit if someone click on one of the submit
I am using JQuery .live to listen for a custom event, ie not .click,
I have something like this and it has been created from jQuery .append(html) <div
I ashamed and frustrated by this question. I'm writing what should be a pretty
I made a custom drop-down list. And I want it to function like the
Been at this for over an hour now - lightbox plugin was working just
I have a problem with the Event object being null when I want to
I'm trying to implement a Soft-deletable repository. Usually this can be easily done with

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.