<a id="address">주소 들어가는 부분</a>
<button id="btn_a_copy">주소 복사</button>
<script type="text/javascript">
document.getElementById('btn_a_copy').onclick = function() {
this.textContent = '복사완료';
const valOfDIV = document.getElementById("address").innerText;
const textArea = document.createElement('textarea');
document.body.appendChild(textArea);
textArea.value = valOfDIV;
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);
}
</script>
<script type="text/javascript">
document.getElementById('btn_a_copy').onclick = function() {
alert('복사되었습니다.');
const valOfDIV = document.getElementById("address").innerText;
const textArea = document.createElement('textarea');
document.body.appendChild(textArea);
textArea.value = valOfDIV;
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);
}
</script>
'Javascript' 카테고리의 다른 글
swiper pagination 두개 사용하기 (0) | 2024.11.06 |
---|---|
스크롤(scroll)시 head/상단에 class 추가 (0) | 2024.02.14 |
text 페이드인,아웃 효과 (fade-in, fade-out) (0) | 2023.11.29 |
swiper 슬라이드 호버시 멈춤 (0) | 2023.11.24 |
주소복사 버튼 (0) | 2023.11.09 |