Disable dragging an image from an HTML page

User 1034 picture User 1034 · Nov 18, 2010 · Viewed 227.1k times · Source

I need to put an image in my page. I want to disable dragging of that image. I am trying lot of things but no help. Can somebody help me out ?

I don't want to keep that image as a background-image because I am resizing the image.

Answer

alex picture alex · Nov 18, 2010

You can like this...

document.getElementById('my-image').ondragstart = function() { return false; };

See it working (or not working, rather)

It seems you are using jQuery.

$('img').on('dragstart', function(event) { event.preventDefault(); });