<textarea id="main-text" rows="5" cols="30">내용을 작성 후 다른 곳에 붙여넣어보세요.</textarea>
<button id="btn-copy">클립보드에 복사</button>
function copyToClipboard(text) {
  var t = document.createElement("textarea");
  document.body.appendChild(t);
  t.value = text;
  t.select();
  document.execCommand("copy");
  document.body.removeChild(t);
  alert("복사되었습니다.");
}

var btnCopy = document.getElementById("btn-copy")
    
btnCopy.addEventListener("click", function (e) { 
  var text = document.getElementById("main-text").value
  copyToClipboard(text)
})


External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.