How to disable right click on div using context menu jquery?

Today now in this post i will show you How to disable right click on div using context menu jquery? Now here i am going to tell you about how to disable mouse right click on any div. By using this example we can learn about how to disable the right click on any html or any page or image tag.

We know jquery provide us contextmenu event on that way we can prevent the right click on any specific html element. So in this example i will used contextmenu event with on().

So, let’s see the example code and try by own.

Disable right click Example:

<html lang="en">
<head>
  <title>Jquery - disable right click on div using context menu </title>
  <script src="http://demo.itsolutionstuff.com/plugin/jquery.js"></script>
</head>
<body>
<div class="container">
	<div class="my-div" style="width:500px;height:500px;background:red"></div>
</div>
<script type="text/javascript">
	$(document).ready(function() {
	    $(".my-div").on("contextmenu",function(){
	       return false;
	    }); 
	});
</script>
</body>
</html>

Read Also: How to Get Current URL with Parameters in Laravel?

Thanks for read. I hope it help you. For more you can follow us on facebook

Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.