function copyFunction() {
// Result container
const resultContainer = document.getElementById('result-container');
// Get texts
const copyText1 = document.getElementById("p1").textContent;
const copyText2 = document.getElementById("p2").textContent;
// Get positions
const rect1 = document.getElementById("p1").getBoundingClientRect();
const rect2 = document.getElementById("p2").getBoundingClientRect();
const mainrect = document.getElementById("main").getBoundingClientRect();
// Get positions relative to 'main'
resultContainer.textContent = copyText2;
/*alert(copyText);*/
/*
const textArea = document.createElement('textarea');
textArea.textContent = copyText;
document.body.append(textArea);
textArea.select();
document.execCommand("copy");
*/
}
function render(relativeRect, text) {
// Måste man kanske rendera "rad-för-rad" "uppifrån-och-ner" för att det skall bli rätt?
// Eller i en TEXTAREA med Insert satt kanske?
}
function calculateOffset(childPos, parentPos){
var relative = {};
relative.top = childPos.top - parentPos.top;
relative.right = childPos.right - parentPos.right;
relative.bottom = childPos.bottom - parentPos.bottom;
relative.left = childPos.left - parentPos.left;
return relative;
}
document.getElementById('copy').addEventListener('click', copyFunction);
// If you need to place cursor
//https://stackoverflow.com/questions/34968174/set-text-cursor-position-in-a-textarea
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.