0

Demo - http://jsfiddle.net/P9rs6/

HTML

<span class="js-make-input" data-id="1" data-value="5">5</span>

jQuery

    $('.js-make-input').on('dblclick', function(){
    var itemID = $(this).attr('data-id');
    var value = $(this).attr('data-value');

    $(this).attr('class', 'js-edit-row');

    $(this).html(' <input type="text" value="' + value + '" data-id="' + itemID + '" style="width: 45px" /> ');
});

$('.js-edit-row').on('dblclick', function(){
    $(this).attr('class', 'js-make-input');
    $(this).html(value);
    var value = $(this).attr('data-value', value);

});

I can understand, why it doesn't work after second dblclick.

md_bender
  • 13
  • 1

1 Answers1

2

You may use on() for binding events on dynamically added elements. Like this:

$(document).on('dblclick','.js-make-input', function(){ /*Your code here*/ });

This is just for simple example, it is better to bind it on element closer to your button that is already on page when it first loads rather than on document.

Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125