userSelect 사용 JavaScript의 속성을 사용하여 텍스트 선택을 활성화하거나 비활성화합니다. Firefox의 경우 MozUserSelect 속성을 선택하고 선택을 비활성화하려면 없음으로 설정하십시오.
다음 코드를 실행하여 JavaScript로 요소의 텍스트를 선택할 수 있는지 여부를 설정할 수 있습니다 -
예시
<!DOCTYPE html>
<html>
<body>
<button onclick = "myFunction()">Click me</button>
<div id = "box">
Click the above button. This won't allow you to select this text. Shows ths usage of userSelect property.
</div>
<script>
function myFunction() {
var a = document.getElementById("box");
a.style.userSelect = "none";
// Works in Chrome and Safari
a.style.WebkitUserSelect = "none";
// Works in Firefox
a.style.MozUserSelect = "none";
}
</script>
</body>
</html>