pretty
pretty

Reputation: 67

How to disable all mouse events in a web page in HTML or Javascript

I place the text on the image inside the label. If I drag the text and place it in a text box it automatically copies that text. But i don't want that to be happened. Please give me a hint to disable the mouse click and drag event on the text.

Upvotes: 1

Views: 3072

Answers (1)

Ehsan
Ehsan

Reputation: 12959

this help you :

<html>
<head>
</head>
<body>
   <span id="txt" draggable="false">This is test</span>
    <script>
        var txt = document.getElementById("txt");
         txt.addEventListener("click",function(event){event.preventDefault();})
        txt.addEventListener("mousedown",function(event){event.preventDefault();})
         txt.addEventListener("mouseup",function(event){event.preventDefault();})
          txt.addEventListener("contextmenu",function(event){event.preventDefault();})
    </script>
</body>

</html>

Upvotes: 6

Related Questions