Guy P
Guy P

Reputation: 1423

Prevent all images from being dragable except predefined images (HTML 5)

All images are draggable="true" by default.

How can I prevent all images (and also user selected segments) in a page to be dragable, except few images.

I'm looking for a dynamically code in JS and not HTML code (by addEvent() function).

For example Here: http://html5demos.com/drag you can drag and drop the HTML5 logo inside the trash image, case that was not supposed to happen.

Upvotes: 2

Views: 87

Answers (1)

robertc
robertc

Reputation: 75707

Prevent the dragstart event:

document.addEventListener('dragstart', function(e) { e.preventDefault(); });

The usual cross browser event attaching provisos apply.

Upvotes: 2

Related Questions