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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:02:54+00:00 2026-06-18T17:02:54+00:00

I have written my code such that when user double clicks on a <td>

  • 0

I have written my code such that when user double clicks on a <td> element I am:

  • appending am <input> of type="text"
  • adding a value to it and update it if the user clicks on enter

Here is the my problem:

If user double clicks on <td> and clicks on another <td> without pressing enter, I need the initial <td>‘s <input> to be reset to previous value.

// Selecting the table <th> odd elements
$("#div table td").dblclick(function(){
    var currentEle = $(this);
    var value = $(this).html();
    updateVal(currentEle, value);
});

function updateVal(currentEle, value)
{
    $(currentEle).html('<input class="thVal" type="text" value="'+value+'" />');
    $(".thVal").focus();
    $(".thVal").keyup(function(event){
        if(event.keyCode == 13){
            $(currentEle).html($(".thVal").val().trim());
        }
    });

    $('body').not(".thVal").click(function(){
        if(('.thVal').length != 0)
        {
            $(currentEle).html($(".thVal").val().trim());
        }
    });
}

Please help me.
I don’t want to use jeditable datatable.

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

    Here in your case you need .stopPropagation(): http://jsfiddle.net/jFycy/

    $(function () {
        $("#div table td").dblclick(function (e) {
           e.stopPropagation();      //<-------stop the bubbling of the event here
           var currentEle = $(this);
           var value = $(this).html();
           updateVal(currentEle, value);
        });
    });
    
    function updateVal(currentEle, value) {
      $(currentEle).html('<input class="thVal" type="text" value="' + value + '" />');
      $(".thVal").focus();
      $(".thVal").keyup(function (event) {
          if (event.keyCode == 13) {
              $(currentEle).html($(".thVal").val().trim());
          }
      });
    
      $(document).click(function () { // you can use $('html')
            $(currentEle).html($(".thVal").val().trim());
      });
    }
    

    Instead doing click on body do the event on document or html which is the parent elem of all others elems.

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

Sidebar

Related Questions

I have written some physics simulation code in C++ and parsing the input text
I have written this code to convert string in such format 0(532) 222 22
I have written code that opens 16 figures at once. Currently, they all open
I have written code to perform a function that could take a while to
I have written some code that loads an XML document using an XmlDocument object
I have written some VSTO (2003) code that sucessfully applies some mandatory subject line
I have written a user control for our SharePoint site that builds an HTML
I have a piece of code written using VS 2005 that works fine in
Let's say I have a greasemonkey-type user script running on a page that has
I have written code in Java to access web cam,and to save image... I

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.