A JavaScript Library for Adding Context Menus to Any HTML Element | context-menu.js

A context menu is a small (4.4kb / 1.7kb compressed) JavaScript library for adding that helps you create custom, dynamic, and original-looking context menus within any container element you select.

javascript context menu example, custom right click menu, javascript context menu library, custom right click menu jquery, javascript add to context menu, contextmenu

Table of Contents

How to make use of it:

Install and import the context-menu.js into your undertaking.

$ npm install context-menu --save
// ES 6
import ContextMenu from 'ContextMenu';

// CommonJS:
const ContextMenu = require('ContextMenu');

Include the UMD version of context-menu.js on the net web page.

<script src="context-menu.js"></script>

Define the menu objects within the JavaScript:

var items = [
    { name: 'Cut', fn: function(target) { console.log('Cut', target); }},
    { name: 'Copy', fn: function(target) { console.log('Copy', target); }},
    { name: 'Paste', fn: function(target) { console.log('Paste', target); }},
    { name: 'Select All', fn: function(target) { console.log('Select All', target); }},

Attach the context menu to a component.

<div class="default" tabindex="0">Default theme</div>
var myMenu = new ContextMenu('.default', items);

Add an extra CSS class to the context menu. Useful for {custom} menu styles.

var myMenu = new ContextMenu('.default', items,{
    className: 'custom-theme',
    minimalStyling: true

Event listeners.

// events: created, shown, hidden, itemselected
instance.on('shown', function);
instance.off('shown', function);


  • selector (String) – Show context menus for elements matching this selector
  • items (Array) – Array of menu items objects in the format of:
    • name (String) – Label displayed for menu item
    • fn (Function) – onclick the event handler for menu item
    • Note: to insert a divider, insert an empty object ({}) in the items array.
  • options (Object)
    • className (String, default: '') – CSS class to add to the context menu element
    • minimalStyling (Boolean, default: false) – If true, does not apply default theme CSS class to context menu element

Create Custom Context Menus, context-menu Plugin/Github

See Demo And Download

Official Website(mturco): Click Here

This superior jQuery/javascript plugin is developed by mturco. For extra Advanced Usages, please go to the official website.

Related Posts


How to Create a Simple Cookie Banner Consent Using Bootstrap 4

Cookie Consent Popup Javascript – Quick and simple tutorial for creating a simple Bootstrap cookie banner. If you have a website or blog with people visiting or…


Create Custom HTML Terminals With Pure JavaScript | shell.js

Custom HTML Terminals is A JavaScript library to create HTML terminals on web pages. The shell js JavaScript library offers a straightforward method to create Ubuntu, OS X,…


Bootstrap Alert, Confirm, and Flexible Dialog Boxes | Bootbox

Bootbox.js is a small JavaScript library that allows you to create programming dialogs using Bootstrap templates, without having to worry about creating, managing, or removing any required…


An Accessible Touch-enabled Slider Web Component | fg-carousel

fg-carousel Slider – A simple & modern slider web component to create versatile, accessible, touch-enabled picture carousels utilizing CSS scroll snap, Custom Element, and Intersection Observer API….


A Lightweight and Efficient Tags Input Component in Vanilla JS | tagify

tagify transforms an input field or textarea into a tags component, in an easy and customizable way, with great performance and a small code footprint, full of…


A Lightweight Library to Copy Text to Clipboard | CopyJS

CopyJS is a lightweight JavaScript library that allows you to copy plain text or HTML content to the clipboard. Must Read: Tiny Library for Copy Text In…