views:

92

answers:

3

I have this, text, that when you click on it, you can edit it and when you click somewhere else it will store it to the database(by sending ajax call), and your edited new text will show.

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

Try clicking at the text, and you will see it become a field and so.

Here's my current code: http://jsbin.com/ewihu3/edit

I know how to make ajax call in jquery, but i dont know how to make a on click function that turns the text to a field with the text and when done it should be text-format again with the new text you just edited it too..

How can i do this?

A: 

Yes, this can be done easier with jQuery.

espais
+1  A: 

This is simple:

<span>Click to edit me</span>​

$('span').bind('click', function(){
   this.contentEditable = true;
});​

http://www.jsfiddle.net/7A6MQ/2/

jAndy
That can be done easier ;), besides, that's HTML5 only. Also, it makes no sense to use javascript to set it to true...
Dykam
Karem
@Dykam: I wasn't too serious about the answer, but I'm really interested how you like to change the state without javascript.
jAndy
@jAndy: `<span contenteditable="true">Click to edit me</span>​` Not changing element state, but setting it correctly at first.
Dykam
@Dykam: You didn't get the point I guess. OP's intention was to make something editable when clicking on it.
jAndy
A: 

I would not use contentEditable as it is not supported by older IE versions.

pondpad
@pondpad - This would be better as a comment on an answer rather than a standalone answer.
geoff