Multi-level Custom Context Menu Made Easy – ctxmenu.js
You can specify custom context menus for different elements, use JavaScript functions or HTML links for interactive items, and create infinite nested submenus.
It’s fully customizable, has built-in dark mode support, and works great across devices like desktop and mobile.
1. Install and import the ctxmenu with NPM.
# NPM $ npm install ctxmenu
import { ctxmenu } from "ctxmenu"; 2. Or download the package and load the minified version of the ctxmenu.js library in the document.
<script src="ctxmenu.min.js"></script>
3. Define your menu items in a JS array as follows:
const myMenu = [
// Menu 1 Header
{
text?: string | () => string,
tooltip?: string | () => string,
html?: string | () => string,
element?: HTMLElement | () => HTMLElement,
icon?: string | () => string,
style?: string | () => string,
events?: EventRegistry | () => EventRegistry,
attributes?: Record<string, string> | () => Record<string, string>
},
// Menu 1 Item
{
// Standard props here
action: (event: MouseEvent) => void,
disabled?: boolean | () => boolean
},
// Divider
{ isDivider: true },
// Menu 2 Header Here
// Menu 2 Item
{
// Standard props here
href: string | () => string,
target?: string | () => string,
disabled?: boolean | () => boolean
},
// Has sub menu
{
subMenu: [
// sub menus here
]
}
] 4. Attach the context menu to the element you specify.
ctxmenu.attach(".myElement", myMenu, {
// configs
onBeforeShow?: (menu: CTXMenu, event?: MouseEvent) => CTXMenu;
onShow?: (dom: HTMLUListElement) => void;
onBeforeHide?: (dom: Element) => void;
onHide?: (dom: Element) => void;
attributes?: Record<string, string>
}) 5. More API methods.
// Update the context menu ctxmenu.update(target: string, ctxmenu?: Array, beforeRender?: (menu: Array, event: MouseEvent) => Array) // Delete the context menu from a container element ctxmenu.delete(target: string) // Show the context menu with a custom mouse event ctxmenu.show(ctxmenu: Array, e: MouseEvent | HTMLElement) // Hide the context menu ctxmenu.hide()
v2.1.0 (01/21/2026)
v2.0.2 (02/12/2025)
v2.0.1 (01/27/2025)
v2.0.0 (01/03/2025)
v1.7.0 (03/14/2024)
The post Multi-level Custom Context Menu Made Easy – ctxmenu.js appeared first on CSS Script.
As media executives, we often look for the “magic bullet” software that solves our efficiency…
For many media and broadcast organizations, cloud infrastructure has evolved from a path to flexibility…
The post Avid’s New CPO Discusses AI, NAB Show & Newsroom Tech appeared first on…
The post BCNEXXT Adds HLG-Based HDR To Vipe Platform appeared first on TV News Check.
Stadium Sports Network is using Telycam Explore XE cameras to upgrade visual quality for its…
Gracenote, the content data business unit of Nielsen, is helping Samsung Electronics, a global provider…
This website uses cookies.