OKAY, BIG EDIT: I think I understand the problem here, so even after changing the code previously provided so that it's selecting properly, when you copy it only copies the bottom text field. I think this is because copy just isn't supposed to work for multiple textareas at once.
My solution for this is to create a new element with JS, have what I want to copy put in that element, select and copy from there? In my head, this works, but I'm not sure how I would go about actually doing that.
Here's what I tried, but I'm sort of pulling from nothing so it's riddled with errors. I'm very new to JS so I'm sorry how much I don't understand! I used to have this code in the main.js file, but every time I mess something up in it, it throws off the whole thing so I've moved it to its own dohtml-copier.js file.
<!DOCTYPE html>
<html>
<head>
<title>Live Editor</title>
<link rel="stylesheet" type="text/css" href="assets/css/style.css">
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@200;400;700;900&display=swap" rel="stylesheet">
<script type="text/javascript" src="assets/js/jquery.js"></script>
<script type="text/javascript" src="assets/js/jquery-ui.js"></script>
</head>
<body>
<div class="le-header">live editor by emilie <button class="le-click" onclick="getDOHTML();">copy dohtml</button></div>
<div class="le-wrap">
<div class="le-result">
<iframe id="le-preview" src="">
<!DOCTYPE html><html>
<head>
</head>
<body>
</body>
</html>
</iframe>
</div>
<div class="le-code">
<button class="le-tit">HTML</button>
<div class="le-pannel">
<textarea id="le-html" onkeyup='saveValue(this);'></textarea>
</div>
<button class="le-tit">CSS</button>
<div class="le-pannel">
<textarea id="le-css" onkeyup='saveValue(this);'></textarea>
</div>
<button class="le-tit">JavaScript / JQuery</button>
<div class="le-pannel">
<textarea id="le-js" onkeyup='saveValue(this);'></textarea>
</div>
</div>
</div>
<script type="text/javascript" src="assets/js/main.js"></script>
<script type="text/javascript" src="assets/js/dohtml-copier.js"></script>
</body>
</html>
function getHTML() {
var html = $('#le-html').val();
return html;
}
function getCSS() {
var html = $('#le-css').val();
return html;
}
function getJS() {
var html = $('#le-js').val();
return html;
}
function getDOHTML() {
var dohtml = document.createElement('dohtml');
dohtml.append("[dohtml]<center><style>" + getCSS(); + "</style>" + getHTML(); + "<script>" + getJS(); + "<\/script></center>[/dohtml]");
dohtml.select();
document.execCommand("copy");
alert("Created + Copied DOHTML");
};