I need to toggle between input and text on click. Something like live edit.
I wrote this code, but it doesn't work.
HTML:
<span class="editInput">Change the value on click</span>
<button>Click me</button>
JS:
var editmode = false;
$('button').on('click',function(){
if(editmode){
$('.editInput').replaceWith(function(){
return '<span class='+this.className+'>'+this.value+'</span>';
editmode = false;
})
}else {
$('.editInput').replaceWith(function(){
return '<input type="text" value='+this.text+' class='+this.className+'/>';
editmode = true;
})
}
})
Can someone help me?