rista404 rista404 - 1 year ago 112
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?

Answer Source

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 {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download