Advanced User Interface Controls and Components

Menu Item as Separator in jQuery

Created: 31 July 2014

All items in Menu widget for jQuery can act as normal item showing title, hyperlink, custom content or act as a separator. The menu item object has a property type which determined the behavior of the item.

Menu is part of IntegralUI Studio for Web
a suite of UI Components for development of web apps

In order for an item to act and appear as a separator we can set this during design time using HTML5 or though code using javascript. In both cases the result is similar; the only difference is whether we know how our menus will look like during design time or menus are created dynamically from local or remote data source.

At first lets create a simple web page which contains a Menu widget:


var $menuBar = $('#menu').menu({

openOnHover: true



<!DOCTYPE html>

<html xmlns="" >


<link rel="stylesheet" href="css/" />

<link rel="stylesheet" href="css/themes/theme-dark.css" />

<script type="text/javascript" src="external/jquery-1.9.1.min.js"></script>

<script type="text/javascript" src="external/jquery.ui.core.min.js"></script>

<script type="text/javascript" src="external/jquery.ui.widget.min.js"></script>

<script type="text/javascript" src="js/jquery.integralui.widget.min.js"></script>

<script type="text/javascript" src="js/"></script>



<div id="menu" class="widget"></div>



<style type="text/css">



width: 600px;

height: 0;



Using HTML5 Attribute to Create a Separator Item

We can create a separator with HTML5 custom attribute, in this case use the data-element attribute and set its value to separator. Here how looks the HTML5 code for the File menu and its submenus:

<div id="menu" class="widget">




<li><span class="icons new" data-element="icon"></span><span>New</span>







<li><span class="icons save" data-element="icon"></span><span>Save As...</span></li>

<li><span>Save All</span></li>

<li><hr data-element="separator" /></li>

<li><span>Page Setup</span></li>

<li><span class="icons print" data-element="icon"></span><span>Print</span></li>

<li><hr data-element="separator" /></li>






<style type="text/css">



background-image: url(../images/icons-business.png);

background-repeat: no-repeat;

display: inline-block;

overflow: hidden;

padding: 0;

margin: 0 1px;

width: 16px;

height: 16px;




background-position: 0px 0px;




background-position: -16px 0;




background-position: -32px 0;




background-position: -48px 0;



Using jQuery to Create a Separator Item

In order to make an item act as a separator through code we need to change the type property of the item object, and set its value to separator string.

var item = {

type: "separator"


We can create the content of the menu like in demonstration above entirely from code, here is the code for the File menu with its submenus:

var data = [


id: 1,

text: "File",

items: [


id: 11,

pid: 1,

text: "New",

icon: "<span class='icons new' data-element='icon'></span>",

items: [

{ id: 111, pid: 11, text: "Project" },

{ id: 112, pid: 11, text: "Window" }



{ id: 12, pid: 1, text: "Open" },

{ id: 13, pid: 1, text: "Save As...", icon: "<span class='icons save' data-element='icon'></span>" },

{ id: 14, pid: 1, text: "Save All" },

{ id: 15, pid: 1, type: "separator" },

{ id: 16, pid: 1, text: "Page Setup" },

{ id: 17, pid: 1, text: "Print", icon: "<span class='icons print' data-element='icon'></span>" },

{ id: 18, pid: 1, type: "separator" },

{ id: 19, pid: 1, text: "Exit" }





// Load the data to the menu using the AddItem method

// Because our data is a tree structure, we can cycle only through root items, all child items are added automatically

for (var i = 0; i < data.length; i++)

$"addItem", data[i]);

You will notice that items that act as separator only have a value set for type property to a "separator" string.

You can change the appearance of separators whatever you like. Using custom CSS3 styles you can modify it and set to match its look to your web application theme. In our case we are using a <hr> as a separator and the appearance is set using this style:

.widget hr


background: #ebebeb;

border: 0;

border-bottom: 1px solid #fafafa;

color: #ebebeb;

margin: 0;

height: 1px;



Sign-up to our newsletter and you will receive news on upcoming events, latest articles, samples and special offers.
Name: Email: *
*By checking this box, I agree to receive a newsletter from Lidor Systems in accordance with the Privacy Policy. I understand that I can unsubscribe from these communications at any time by clicking on the unsubscribe link in all emails.