view raw
rista404 rista404 - 6 months ago 51
HTML Question

Jquery: Toggle between input and text on click

I need to toggle between input and text on click. Something like live edit.

I wrote this code, but it doesn't work.


<span class="editInput">Change the value on click</span>
<button>Click me</button>


var editmode = false;

return '<span class='+this.className+'>'+this.value+'</span>';
editmode = false;
}else {
return '<input type="text" value='+this.text+' class='+this.className+'/>';
editmode = true;


Can someone help me?


Check out this Fiddle. It's not very elegant, but I think it's a quick, cleaner solution than what you were doing. Let me know if you have any more questions.


span {

    if($("input").is(":visible")) {  
    } else {