views:

40

answers:

1

Right now I have this in Javascript without jQuery:

Here is it: http://jsbin.com/ewihu3

It's working just fine, but I wish to use jQuery for making the code simpler and shorter.

I want exactly same things to do as on the example above, that when you click on the text, it should turn into an input field. And on blur it should display what you've edited in the box, and then make a variable (like e.value on the example above) so I can send that in a ajax call later.

How can i do this in jQuery?

A: 

You can use the jEditable plugin

Or you can start something similar pretty simply by yourself too, with something like this:

$('span.editable').click(function() {
   var input = $('<input type="text" />', {
      value: $(this).text()
   }).click(function() {
      $.get('editsave.php?tekstny=' + $(this).value(), function(response) {
         var span = $('span', {
            text: response
         });
         $(this).replaceWith(span);
      });
   });
   $(this).replaceWith(input);
});
PJP
Hello. I get error in an unknown function in the jquery library when using this code. And jEditable, afterwards its saving/call it makes, it doesnt show the new value after
Karem
Your server-side script has to "echo" the new value, and jEditable will show this value after saving.Unknown function error in jQuery? Do you get the name of this unknown function? Maybe you're using an old jQuery release?
PJP