To disable dragging an image from an HTML page with JavaScript, we stop the default action for the dragstart event.
For instance, we write
document.getElementById("my-image").ondragstart = () => {
return false;
};
to select the img element with getElementById.
Then we set its ondragstart property to a function that returns false to stop the default drag action to stop the img element from being dragged.