Drag and Drop is a very interactive and user-friendly concept which makes it easier to move an object to a different location by dragging it. It allows the user to click and hold the mouse button over an element, drag it to another location, and release the mouse button to drop the element there. In HTML 5 Drag and Drop are much easier to code and any element in it is draggable. Links and images are by default draggable. This feature is mostly enabled on most of the websites. Google is even allowing the users to do an image search using the image drag and drop feature, also known as the image dragging feature.
This feature enables the user to click on any image, and then drag it elsewhere. This creates a transparent copy of the clicked image while keeping the original image in its place. However, the image dragging feature can be disabled using JavaScript/jQuery.
Method 1: This method sets the dtraggable attribute to false using jQuery.
Syntax:
$('#myImage').attr('draggable', false);
Example:
<!DOCTYPE html> <html> <head> <title> How to disable dragging an image from an HTML page using JQuery? </title> <script src= </script> </head> <body style="text-align:center"> <center> <h1 style="color:green;"> GeeksforGeeks </h1> <h3> Click on the button to disable dragging an image </h3> <button onclick = "myGeeks()"> Disable image dragging </button> <br> <img id="img" src= <script type="text/javascript"> function myGeeks() { $('#img').attr('draggable', false); } </script> </body> </html> |
Output:

Method 2: This method sets the dtraggable attribute to false using JavaScript.
Syntax:
document.getElementById('myImage').draggable = false;
Example:
<!DOCTYPE html> <html> <head> <title> How to disable dragging an image from an HTML page using JQuery? </title> <script src= </script> </head> <body style="text-align:center"> <center> <h1 style="color:green;"> GeeksforGeeks </h1> <h3> Click on the button to disable dragging an image </h3> <button onclick = "myGeeks()"> Disable image dragging </button> <br> <img id="img" src= <script type="text/javascript"> function myGeeks() { document.getElementById('img').draggable = false; } </script> </body> </html> |
Output:

Recommended Posts:
- How to prevent dragging of ghost image ?
- How to disable right click on web page using JavaScript ?
- How to disable zoom on a mobile web page using CSS?
- How to trigger onchange event on input type=range while dragging in Firefox ?
- How to redirect a page to another page in HTML ?
- How to display search result of another page on same page using ajax in JSP?
- HTML | Responsive full page image using CSS
- How to disable HTML links using JavaScript / jQuery ?
- How to show Page Loading div until the page has finished loading?
- How to pass form variables from one page to other page in PHP ?
- Convert an image into grayscale image using HTML/CSS
- How to disable text selection highlighting using CSS?
- How to disable a link using only CSS?
- How to disable resizable property of textarea using CSS?
- How to disable scrolling temporarily using JavaScript?
- How to disable scroll to change number in <input type="number"> field using JavaScript/jQuery?
- How to enable/disable all input controls inside a form element using jQuery ?
- How to disable arrow key in textarea using JavaScript ?
- How to disable Copy, Paste, Cut and Right Click using jQuery ?
- How to disable scrollbar without hiding using jQuery ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


