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?
2 Answers
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>
1 Comment
Coolsugar
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.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
Coolsugar
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?
Velid Duranović
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