html - Jquery: Toggle between input and text on click -
html - Jquery: Toggle between input and text on click -
i need toggle between input , text on click. live edit.
i wrote code, doesn't work. html:
<span class="editinput">change value on click</span> <button>click me</button>
js:
var editmode = false; $('button').on('click',function(){ if(editmode){ $('.editinput').replacewith(function(){ homecoming '<span class='+this.classname+'>'+this.value+'</span>'; editmode = false; }) }else { $('.editinput').replacewith(function(){ homecoming '<input type="text" value='+this.text+' class='+this.classname+'/>'; editmode = true; }) } })
can help me?
check out fiddle. it's not elegant, think it's quick, cleaner solution doing. allow me know if have more questions.
<div> <input/> <span>test</span> </div> <button>update</button> span { display:none; } $('button').on('click',function(){ if($("input").is(":visible")) { $("input").hide(); $("span").text( $("input").val() ).show(); $("button").text("edit"); } else { $("span").hide(); $("input").text( $("span").val() ).show(); $("button").text("update"); }
});
jquery html input
Comments
Post a Comment