Articles in this section
Category / Section

How to exclude context menu for certain elements within contextmenu's target and display browser's context menu?

1 min read

To prevent the ejContextMenu in specific elements, those elements should be mentioned in the excludeTarget property in JavaScript Menu. Refer to the following code.

$(function(){
        $("#contextMenu").ejMenu({ menuType:ej.MenuType.ContextMenu,contextMenuTarget:"#target",excludeTarget: ".inner,.inner2" });  
});

 

Note:

Class and ID attributes can be used in the excludeTarget property. Multiple attributes can be separated by (,) comma.

 

For more information, refer to the API documentation for the excludeTarget property.

Now to show the browser’s context menu in the excluded elements, the internal _contextMenuEvents method should be overridden. Refer to the following code.

ej.Menu.prototype._contextMenuEvents = function (action) {
    this[action]($(this.model.contextMenuTarget), "mouseup taphold", this._ContextMenuHandler);
    this[action](this.element, "contextmenu", this._onDefaultPreventer);
    this[action]($(document), "mousedown", this._onContextClose);
};

 

Refer to the Playground Sample for Demo.


Conclusion

I hope you enjoyed learning about how to exclude context menu for certain elements within contextmenu's target and display browser's context menu.

You can refer to our JavaScript Menu feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our JavaScript Menu example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied