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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:35:49+00:00 2026-06-07T12:35:49+00:00

I have an event handler attached to a class, as so: $(‘#container’).on(‘click’, ‘.myClass’, function

  • 0

I have an event handler attached to a class, as so:

$('#container').on('click', '.myClass', function (e) {...

Within this handler I want to attach a different click handler to the element that has been clicked. When the temporary handler has been clicked, I want to re-enable the original handler.

What I’m trying to do (as shown in this fiddle) is allow a section of text to be clicked, change that to an input text box, and then submit the change to recreate the text.

I’ve tried the following without success as found at the fiddle:

$('#container').on('click', '.submit', function (e) {
    var $this = $(this),
        new_text = $this.prev().val();
    e.stopPropagation();
    $this.parent().off('click.temp').html(new_text);                    
});

$('#container').on('click', '.test', function (e) {
    var $this = $(this);
    $this.html("<input type='text' value='" + $this.text() + "'/><input class='submit' value='Submit' type='submit'>");
    $this.on('click.temp', function (e) {
        e.stopPropagation();
    });
});

Using an .off() doesn’t seem to cancel the original handler on the class because it is attached to the class not the element.

I think I’ve partly answered my question with e.stopPropagation(), but it’s still not quite working and I’m not convinced I’m going about this the best way 🙂

Note: This post relates to the idea but does not use this.

  • 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-07T12:35:52+00:00Added an answer on June 7, 2026 at 12:35 pm

    Rather than adding and removing handlers for the inputs on the fly, I’d stick with delegated event handlers like you’re already doing in the click handler that creates the inputs:

    $('#container').on('click', '.test', function (e) {
        var $this = $(this);
        $this.removeClass("test")
             .html("<input type='text' value='" + $this.text() + "'/><input id='me' value='Submit' type='button'>");
    });
    
    $('#container').on('click', 'input[type="button"]', function (e) {
        var $this = $(this),
            new_text = $this.prev().val();
        $this.parent().addClass("test")
                      .html(new_text);
    });
    

    On click of a ‘.test’ div replace its contents with inputs like you were doing, but also remove the “test” class so that further clicks on the div won’t do anything (for the moment).

    On click of a submit button change the div back to just show the text, and add the class back again so that the previous click handler takes effect again.

    Note: I’ve changed your buttons from type="submit" to type="button" because they’re not actually used to submit a form.

    Demo: http://jsfiddle.net/4vmQ4/5/

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

Sidebar

Related Questions

Setup: I have attached an event handler on the WebBrowser control something like this...
I have an image with a click event handler that captures the location where
I have an event on one of my classes that I want to attach
I have a search form: <form class=searchForm id=topSearchForm action=/search.ds> that has an onsubmit-event attached
I have an onbeforeunload event handler attached to the page which executes every time
I have an event handler that needs to determine a type and execute code
I have an event handler that will remove an element from a list of
I have an event handler bound to the hover event using the .hover method,
I have an event handler for the TextBox.TextChanged event on a form of mine.
Suppose I have a event handler which makes two AJAX calls to the server:

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.