jquery - Hide input and output entered value as text with ability to change the value by showing input -


could please advice me plugin or solution on jquery.

i need have input field email type. when entered shows on image attached.

change on click

you can click on change link , input shown again value.

what best way that?

thanks!

you plugin jeditable or implement custom solution following:

html

<label for="email">email:</label> <div id="email">eugene@gmail.com</div> <a href="#" id="changeemail" data-target="email">change</a> 

js

// switch input // $('#changeemail').bind('click', function(e){      // prevent switch if input //     if ($(this).get(0).tagname != 'input') {         var $target = $('#'+$(this).data('target')); // target element         var val = $target.text(); // current target value          // swap elements //         $target.replacewith('<input id="email" type="text" value="'+val+'" />');          // hide change //         $('#changeemail').hide();     } });  // switch div // $(document).delegate('#email', 'blur', function(){      // prevent switch if input empty //     if ($(this).val() != ''){         $(this).replacewith('<div id="email">'+$(this).val()+'</div>');         $('#changeemail').show();     } else {         $('#changeemail').hide();     } }); 

updated demo here

i hope helps!


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -