I want to use the text area to switch between HTML code and preview html
When clicked on the HTML, it will show the code for the hidden text area When clicking HTML again it will show
againI want to design something like this
I have tried before
<style> .container { width:500px; position: fixed; } .right-element { background: red; display: inline-block; position: absolute; right: 0; } </style> <div class="container"> <div class="right-element"> Preview </div> <textarea id="w3review" name="w3review" style="position:relative;width:100%;height:75%;resize: none; " ><h3>At w3schools.com you will learn how to make a website. They offer free tutorials in all web development technologies.</h3></textarea> </div>
You can have another
div
dedicated to showing the preview. Then, when the user switches the HTML view, insert the textarea's value into theinnerHTML
of thediv
and display it.But this may expose your application to XSS attacks, so use it with caution.