To disable right-click on images using jQuery, we can listen to the contextmenu event on the image element.
Then in the event handler callback, we can return false to prevent right-clicks on images.
For instance, if we have the following image:
<img src='https://picsum.photos/200/300'>
Then we can write:
$('img').bind('contextmenu', (e) => {
return false;
});
to get all image elements with $(‘img’) .
Then we call bind with 'contextmenu' to listen to the contextmenu event.
And in the event handler callback, we return false .
Now when we right-click on the image, we shouldn’t see any context menu displayed.