Getting Started

jqxMenu represents a jQuery menu widget that makes it easy to add menus to your website or web application. With the jqxMenu you can create website menus, customized context menus, or application-style menu bars with just a small amount of scripting.
Every UI widget from jQWidgets toolkit needs its JavaScript files to be included in order to work properly.

The first step is to create html page and add links to the javascript files and css dependencies to your project. The jqxMenu widget requires the following files:


The next step is to create a div element within the body of the html document and add UL for the menu bar and sub menus and LI elements for each menu item.

The last step is to initialize the widget by adding the following script to the html document:

To call a function(method), you need to pass the method name and parameters(if any) in the jqxMenu’s constructor.
$("#jqxmenu").jqxMenu(‘openItem’, itemID);
To set a property(option), you need to pass the property name and value(s) in the jqxMenu's constructor.
$("#jqxmenu").jqxMenu({ autoOpen: false });
To get a property(option), you need to pass the property name to the jqxMenu's constructor.
var autoopen = $("#jqxmenu").jqxMenu('autoOpen');
To bind to an event of a UI widget, you can use basic jQuery syntax. Let’s suppose that you want to get the clicked menu item when the user clicks. The example code below demonstrates how to bind to the ‘itemclick’ event of jqxMenu.
$('#jqxMenu').on('itemclick', function (event) {
var clickedItem = event.args;
});

Basic Vertical Menu Sample

<!DOCTYPE html>
<html lang="en">
<head>
<title id='Description'>jQuery Menu - Vertical Menu Sample</title>
<link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
<script type="text/javascript" src="../../scripts/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxmenu.js"></script>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-2FX5PV9DNT"></script><script>window.dataLayer = window.dataLayer || [];function gtag(){dataLayer.push(arguments);}gtag('js', new Date());gtag('config', 'G-2FX5PV9DNT');</script></head>
<body>
<div id='content'>
<script type="text/javascript">
$(document).ready(function () {
// Create a jqxMenu
$("#jqxMenu").jqxMenu({ width: '120', mode: 'vertical'});
});
</script>
<div id='jqxWidget'>
<div id='jqxMenu'>
<ul>
<li><a href="#">Home</a></li>
<li>About Us
<ul>
<li><a href="#">History</a></li>
<li><a href="#">Our Vision</a></li>
</ul>
</li>
<li>Services
</li>
<li>Products
<ul>
<li><a href="#">New</a>
<ul>
<li><a href="#">Corporate Use</a></li>
<li><a href="#">Private Use</a></li>
</ul>
</li>
<li><a href="#">Used</a>
<ul>
<li><a href="#">Corporate Use</a></li>
<li><a href="#">Private Use</a></li>
</ul>
</li>
<li><a href="#">Featured</a></li>
</ul>
</li>
<li><a href="#">Gallery</a></li>
<li><a href="#">Events</a></li>
<li><a href="#">Careers</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
</div>
</div>
</div>
</body>
</html>

The result of the above code is:

Basic Horizontal Menu Sample

<!DOCTYPE html>
<html lang="en">
<head>
<title id='Description'>jQuery Menu - Horizontal Menu Sample</title>
<link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
<script type="text/javascript" src="../../scripts/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxmenu.js"></script>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-2FX5PV9DNT"></script><script>window.dataLayer = window.dataLayer || [];function gtag(){dataLayer.push(arguments);}gtag('js', new Date());gtag('config', 'G-2FX5PV9DNT');</script></head>
<body>
<div id='content'>
<script type="text/javascript">
$(document).ready(function () {
// Create a jqxMenu
$("#jqxMenu").jqxMenu({ width: 600, height: 30});
});
</script>
<div id='jqxWidget'>
<div id='jqxMenu'>
<ul>
<li><a href="#">Home</a></li>
<li>About Us
<ul>
<li><a href="#">History</a></li>
<li><a href="#">Our Vision</a></li>
</ul>
</li>
<li>Services
</li>
<li>Products
<ul>
<li><a href="#">New</a>
<ul>
<li><a href="#">Corporate Use</a></li>
<li><a href="#">Private Use</a></li>
</ul>
</li>
<li><a href="#">Used</a>
<ul>
<li><a href="#">Corporate Use</a></li>
<li><a href="#">Private Use</a></li>
</ul>
</li>
<li><a href="#">Featured</a></li>
</ul>
</li>
<li><a href="#">Gallery</a></li>
<li><a href="#">Events</a></li>
<li><a href="#">Careers</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
</div>
</div>
</div>
</body>
</html>

The result of the above code is:

Basic Context Menu Sample

<!DOCTYPE html>
<html lang="en">
<head>
<title id='Description'>This demo demonstrates how to use the jqxMenu widget as a Context
Menu. </title>
<meta name="keywords" content="jQuery Menu Widget, Context Menu, jqxMenu, jQuery Widgets, jQuery Plugins, jQuery UI Widgets, jQuery UI" />
<link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
<script type="text/javascript" src="../../scripts/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxmenu.js"></script>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-2FX5PV9DNT"></script><script>window.dataLayer = window.dataLayer || [];function gtag(){dataLayer.push(arguments);}gtag('js', new Date());gtag('config', 'G-2FX5PV9DNT');</script></head>
<body>
<div id='content'>
<script type="text/javascript">
$(document).ready(function () {
// Create a jqxMenu
var contextMenu = $("#jqxMenu").jqxMenu({ width: '120px', height: '140px', autoOpenPopup: false, mode: 'popup'});
// open the context menu when the user presses the mouse right button.
$("#jqxWidget").bind('mousedown', function (event) {
var rightClick = isRightClick(event);
if (rightClick) {
var scrollTop = $(window).scrollTop();
var scrollLeft = $(window).scrollLeft();
contextMenu.jqxMenu('open', parseInt(event.clientX) + 5 + scrollLeft, parseInt(event.clientY) + 5 + scrollTop);
return false;
}
});
// disable the default browser's context menu.
$(document).bind('contextmenu', function (e) {
return false;
});
function isRightClick(event) {
var rightclick;
if (!event) var event = window.event;
if (event.which) rightclick = (event.which == 3);
else if (event.button) rightclick = (event.button == 2);
return rightclick;
}
});
</script>
<div id='jqxWidget' style='vertical-align: middle; text-align: center; background: #eee;
height: 400px; width: 400px;'>
<div id='jqxMenu'>
<ul>
<li><a href="#">Home</a></li>
<li>About Us
<ul>
<li><a href="#">History</a></li>
<li><a href="#">Our Vision</a></li>
</ul>
</li>
<li>Services
<ul style='width:200px;'>
<li><a href="#">Product Development</a></li>
<li><a href="#">Delivery</a></li>
</ul>
</li>
<li>Products </li>
<li><a href="#">Contact Us</a> </li>
</ul>
</div>
<span style='font-size: 14px; position: relative; top: 180px; font-family: Verdana Arial;'>
Right-Click here to Open the Menu </span>
</div>
</div>
</body>
</html>

The result of the above code is: