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.
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(); } });
i hope helps!
Comments
Post a Comment