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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:43:47+00:00 2026-05-27T17:43:47+00:00

For my project i need a editable text ,so i decided to use some

  • 0

For my project i need a editable text ,so i decided to use some plugins but i am also new to jQuery and decided to create my own editable label [inline edit] .

Here is my code :

When user clicks an element with class editable

$(".editable").live("click",function(){

//alert($(this).text());
//CurrentOBJhtml = $(this).text();
if (typeof CurrentOBJhtml == 'undefined' || CurrentOBJhtml =="" )
{
    CurrentOBJhtml = $(this).text();
}


nextHtml = "<input style='border:1px solid red;' type='text' class='hoverable' value='"+CurrentOBJhtml+"'  />";
var c = nextHtml;
$(this).html(c);
$(this).children().focus();//$(this).focus();

return false;


});

When user leaves the hoverable

$(".hoverable").live("focusout",function(){

var Hovertext = $.trim($(this).val());
if (Hovertext == null || Hovertext=="")
{
$(this).parent().text(CurrentOBJhtml);

}
else
{
$(this).parent().text(Hovertext);
}
return false;

});

The Problem is when i start edit first element it works well ,but if there is two element with class editable the second one also getting the value of first one ?

Please check the following example :

<label class='editable'>userMania1</label>
<label class='editable'>userDirection1</label>

i can edit the first label ,but when i click the second one i am getting the value of first one so the second one will be <label class='editable'>userMania1</label> which is incorrect.

Please note that i am little bit new to this technology and trying to learn with my current project,how can i solve this problem?

Thank you.

  • 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-27T17:43:48+00:00Added an answer on May 27, 2026 at 5:43 pm

    Using global variables makes it difficult to reuse part of your code. In jQuery, you can use .data() [docs] to associate arbitrary data with a DOM element.

    Here is a cleaned up version of your code:

    (function() {
        var $input = $('<input style="border:1px solid red;" type="text" />');
        $input.focusout(function(event) {
            event.stopPropagation();
            event.preventDefault();
    
            var value = $.trim($(this).val()) || $(this).parent().data('orig_text');
            $(this).parent().text(value);
        });
    
    
        $(".editable").live("click",function(event){
            if (event.target === this) {
                event.stopPropagation();
                event.preventDefault();
    
                var text = $(this).text();
    
                $(this)
                 .data('orig_text', text)
                 .empty()
                 .append($input.clone(true).val(text))
                 .children('input').focus();
            }
        });
    
    }());
    

    DEMO

    Also note, since jQuery 1.7, you should use .on() [docs] instead of .live() and bind the event handlers directly to the elements if they already exist.

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

Sidebar

Related Questions

In my project I need to create a business object validation layer that will
For a school project I need to create a program and it'd be nice
In my project I need to use third party code, stored in several Git
i have try to create new ndk project in eclipse i have done all
I need :project_owners to invite new :project_participants to a project. Much like in Basecamp,
In my project I need to create objects for each kind of Java Math
In my Xcode project I need to rename my ViewController.m in ViewController.mm , but
I am a novice at implementing jQuery add ons. I'd like to use editable
I am developing a java project. This project need administrator privilege to execute some
In a project i need to set use unicode character set for Configuration Properties>General>Character

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.