Handle drag start event on <img> - Javascript DOM

Javascript examples for DOM:Mouse Event

Description

Handle drag start event on <img>

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//w w  w . j  a  v a2s  . c  om
document.querySelectorAll('img').forEach(el=> {
   el.addEventListener('dragstart', e => {
    e.preventDefault();
    return false;
   });
});
    }

      </script> 
   </head> 
   <body> 
      <img src="http://www.java2s.com/style/download.png" draggable="false">  
   </body>
</html>

Related Tutorials