user285594
user285594

Reputation:

How to disable dragging with mouse click any images?

I have an image <img src="fullscreen.jpg" /> for online driving exams, where the questions are asked using image text and with image embedded. When anyone click the image and drag the mouse it moves the image.

But how can i stop this dragging? So that nobody is allowed to do so.

Upvotes: 2

Views: 15182

Answers (3)

someone
someone

Reputation: 1468

Try any of these 3 if you can't or don't want to use an id or jQuery (cross-browser performance has not been tested):

<img src="http://www.google.com/intl/en_com/images/srpr/logo3w.png" ondragstart='return false;'/>
<img src="http://www.google.com/intl/en_com/images/srpr/logo3w.png" onmousedown='return false;'/>
<img src="http://www.google.com/intl/en_com/images/srpr/logo3w.png" onmousedown='return false;' ondragstart='return false;'/>

Demo

Upvotes: 1

Jason Barry
Jason Barry

Reputation: 758

If you're using jQuery, you're looking for the dragstart event.

$("img").bind('dragstart', function(){
    return false; 
});

Upvotes: 4

DzikiMarian
DzikiMarian

Reputation: 423

$('#id-of-your-image').mousedown(function(){return false});

Of course you may have to use other selector as in your example image has no id attribute.

Upvotes: 7

Related Questions