I have a comment system in which I want to realize inline-editing (when someone knows a good plugin or something similar please don't hesitate to give me a name) and found a Javascript snippet which replaces the text with a textarea and the text as the value of that textarea.
But now I need to add a button (submit button) to that textarea so that the user could save the text he edited.
My code looks now like
<span id="name">comment</span>
<div onclick="replacetext();">test</div>
<script type="text/javascript">
function replacetext(){
$("#name").replaceWith($('<textarea>').attr({ id: 'name', value: $('#name').text() }));
</script>
I've tested it out with $("#name").append('<button>yes</button>'); but it didn't work.
}in your example, it works fine here jsfiddle.net/j08691/adb8X.show(), and.hide()to display the TEXTAREA instead of the DIV. Or alternatively, have a class name on BODY which controls display of various elements on the page, and then set this class.