<textarea id='txt'> <b>Hi</b> </textarea> <button onclick='showvalue()'>ClickMe</button> <script> showvalue = function () { var val=txt.value.replace(/</g,'<').replace(/>/g,'>'); document.write(val); }; </script>