All docs
V21.1
21.2
21.1
20.2
20.1
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

Access the Clicked Item

To access the clicked item, handle the itemClick event. If the event handling function is not going to be changed during the lifetime of the UI component, assign it to the onItemClick property when you configure the UI component.

jQuery
JavaScript
$(function() {
    $("#contextMenuContainer").dxContextMenu({
        // ...
        onItemClick: function(e) {
            var itemData = e.itemData;
            var itemElement = e.itemElement;
            var itemIndex = e.itemIndex;
            // ...
        }
    });
});
Angular
HTML
TypeScript
<dx-context-menu ...
    (onItemClick)="itemClick($event)">
</dx-context-menu>
import { DxContextMenuModule } from 'devextreme-angular';
// ...
export class AppComponent {
    // ...
    itemClick(e) {
        const { itemData, itemElement, itemIndex } = e;
        // ...
    }
}
@NgModule({
     imports: [
         // ...
         DxContextMenuModule
     ],
     // ...
 })
Vue
App.vue
<template>
    <DxContextMenu ...
        @item-click="itemClick"
    />
</template>
<script>
import 'devextreme/dist/css/dx.light.css';

import DxContextMenu from 'devextreme-vue/context-menu';

export default {
    components: {
        DxContextMenu
    },
    methods: {
        itemClick(e) {
            const { itemData, itemElement, itemIndex } = e;
            // ...
        }
    }
};
</script>
React
App.js
import React from 'react';
import 'devextreme/dist/css/dx.light.css';

import { ContextMenu } from 'devextreme-react/context-menu';

class App extends React.Component {
    render() {
        return (
            <ContextMenu ...
                onItemClick={this.itemClick}
            />
        );
    }

    itemClick = (e) => {
        const { itemData, itemElement, itemIndex } = e;
        // ...
    }
}

export default App;

If you are going to change event handlers at runtime, or if you need to attach several handlers to the itemClick event, subscribe to this event using the on(eventName, eventHandler) method. This approach is more typical of jQuery.

JavaScript
var itemClickHandler1 = function(e) {
    // First handler of the "itemClick" event
};

var itemClickHandler1 = function(e) {
    // Second handler of the "itemClick" event
};

$("#contextMenuContainer").dxContextMenu("instance")
    .on("itemClick", itemClickHandler1)
    .on("itemClick", itemClickHandler2);
See Also