CSS /JS to prevent dragging of ghost image?

You can set the draggable attribute to false in either the markup or JavaScript code.

// As a jQuery method: $('#myImage').attr('draggable', false);
document.getElementById('myImage').setAttribute('draggable', false);
<img id="myImage" src="https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon.png">

Or direclty with HTML:

<img id="myImage" src="https://link-to-your.image.com/image.png" draggable="false">

Note that draggable="false" can also used on other HTML elements than img.

Leave a Comment