0

How do I build a site that allows me to code html in it. Where I can type code in a textarea and get the entire output for that code beside the textarea in which I code?

1

2 Answers 2

2

You can use JavaScript; create an id for the button and a div to display the text when the button is clicked:

<html>
<head>
    <title>background</title>
    <style type="text/css">
    
        #text{
            display:none;
        }
    
    </style>
</head>
<body>

    <div id="text">
        My Name Is Anurag.
    </div>
        
    <button id="click">click</button>
        
    <script type="text/javascript">

        document.getElementById("click").onclick= function(){
            var text= document.getElementById("text")
            if(text.style.display=="none"){
                text.style.display="block";
            }else{
                text.style.display="none";
            }
        }

    </script>

</body>
</html>
Sign up to request clarification or add additional context in comments.

1 Comment

I want to type in a <textarea>, click a button, and =have whatever I typed in the textarea to be copiede to the DIV on the click of a button. But thanks a lot.
1

document.getElementById("click").onclick = function() {
  var textDiv = document.getElementById("text")
  var textarea = document.getElementById("textarea");

  textDiv.innerText = textarea.value;
}
<div id="text">
  Here comes text from textarea
</div>
<textarea id="textarea"></textarea>
<button id="click">click</button>

2 Comments

Thanks a lot, but I've already tried this, it works perfectly, but was wondering if there was a way to allow me to use the <body> and <head> tags in this. I'm not if you can do that?
Not sure if I understand your question. but I put the code above on stackblitz so you can see it with <body> and <head> tags. stackblitz.com/edit/js-thbwsx?file=index.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.