w3resource
jquery exercises

jQuery: Right click to toggle background color

jQuery Fundamental - II : Exercise-62

Using jQuery right click to toggle background color.

Sample solution :

HTML Code :

<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-git.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Using jQuery right click to toggle background color.</title>
</head>
<body>
<div></div>
<p>Right click the block</p>
</body>
</html>

CSS Code :

div {
background: red;
color: white;
height: 150px;
width: 150px;
}
div.contextmenu {
background: green;
color: black;
}

See the Pen jquery-fundamental-exercise-62 by w3resource (@w3resource) on CodePen.


Contribute your code and comments through Disqus.

Previous: Display a message when the contextmenu event is triggered on the paragraph elements.
Next: Get the background color of a clicked division.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming