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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:19:46+00:00 2026-06-13T23:19:46+00:00

I am trying to do some inline editing using jquery. The problem i am

  • 0

I am trying to do some inline editing using jquery. The problem i am having is when i create the input text, i cannot change the text. I can not even seem to get focus. It seems like its readonly or disabled. The $( “.sr-label” ).live(“click” is still being called when i try to click in the text field. Do i need to do some kind of unbind or something?

Thanks for any help

<ul>
  <li><span class='sr-label'>label 1</span></li>
  <li><span class='sr-label'>label 2</span></li>
</ul>

my js looks like

$( ".sr-label" ).live("click", function(event){    
     console.log("sr-label");
     var $item = $( this ),
     $target = $( event.target );
     var $pitem = $item.parent();
     newHTML  = '<input id="label_'+$pitem.attr('id')+'" type="text" size="30" '+
                 ' value="'+$item.text()+'"><input class="saveedit" '+
                 ' id="save_'+$pitem.attr('id')+'" type="button" value="save">'+
                 ' <input id="canedit" type="button" value="cancel">';
     $item.html(newHTML);
     return false;
 });

jsFiddle Example

  • 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-13T23:19:47+00:00Added an answer on June 13, 2026 at 11:19 pm

    Click events on elements inside the span propagate up to the span and cause your handler to run again. And your handler replaces the entire contents of the span each time it runs. So it’s not that the input is readonly or disabled, it is that clicking on it removes and recreates it.

    You’ll notice that if you tab into the input with the keyboard then you can type in it since keypresses don’t trigger your click handler.

    “Do i need to do some kind of unbind or something?”

    Well you can’t really unbind .live() in a way that stops it applying to certain elements with that class and not others. If you’d bound individual handlers with .click(), .bind() or the non-delegated form of .on() then you could unbind them one by one.

    What you can do instead is change your selector so that it will only apply for elements that don’t have any child input elements:

    $(".sr-label:not(:has(input))").live("click", function(event){
    

    Demo: http://jsfiddle.net/H2ncm/2/

    However, you should note that .live() is deprecated, so (unless you’re stuck with a really old version of jQuery for some reason) you should switch to the delegation version of the .on() method:

    $(document).on("click", ".sr-label:not(:has(input))", function(event){  
    

    When a click on document occurs jQuery tests whether it was on an element that matches the selector in the second parameter and if so calls your function (otherwise does nothing). Note that ideally you won’t use document, you’ll use an element much closer to the elements in question, e.g., your containing ul element.

    Demo: http://jsfiddle.net/H2ncm/1/

    This is sort of equivalent to adding a simple test within the handler to do nothing if the clicked span already contains inputs:

    if ($item.find("input").length)
       return;
    

    Demo: http://jsfiddle.net/H2ncm/

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

Sidebar

Related Questions

I'm trying to put some inline server tags on a page so I can
I'm trying to create some inline assembly in VC++ 2010 to unpack a RGB
I'm trying to replace some macro subroutines with inline functions, so the compiler can
I'm trying to get some rollovers working using jQuery. The trouble is that the
I am a newbie at jQuery. I was trying some things but I need
I'm using Eclipse with C++ plugins on my macbook, trying some practice projects to
I am trying to remove some inline style that are produced on some tables
I am trying to optimize some arithmetic by using the MMX and SSE instruction
I have been trying to implement Chris Coyier's inline-block + text justify solution to
I want to create an inline-block that will take on some unknown width and

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.