<div oncontextmenu="contextFunction()" id="box"></div>
        div{
            display: block;
            width: 200px;
            height: 200px;
            background: #cb3d3d;
            position: absolute;
            top: 50%; 
            left: 50%;
            transform: translate(-50%,-50%);
            box-shadow: 20px 20px 50px rgba(0, 0, 0, 0.83)
        }

        function contextFunction() {
            alert("The color of the box has changed.")
            let box = document.getElementById("box");
            box.style.background = '#4c4ab7';
        }
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.