Easy Menu provides two JavaScript functions that can be used to add or remove menu items at client side:
AddItem - has the following syntax:
ob_em_EasyMenuID.AddItem(id, type, innerHTML, icon, url, urlTarget, onClientClick, AutoHideMenu, position)
· id - The id of the item to add.
· type - The item type to add (MenuItem, MenuSeparator or any custom defined types).
· innerHTML - The content of the item to add.
· icon - Icon to display for the item
Optional - will only be used if menu uses icons.
· url - Url to open when item is clicked
Optional.
· urlTarget - Frame where url is to be opened
Optional.
· onClientClick - Javascript code to execute when item is clicked
Optional.
· AutoHideMenu - If true, the menu will autohide
Optional.
·
New! position - The position inside menu where you need to be added
Optional.
RemoveItem - method has the following syntax:
ob_em_EasyMenuID.RemoveItem(id)
· id - The id of the item to remove.
Note:
- EasyMenuID is the id of the Easy Menu to which we want to add/remove the item.
- document.getElementById("EasyMenuID").object is the same as ob_em_EasyMenuID.
- If the specified item type doesn't exist for the current menu, MenuItem will be used by default.
Test adding and removing items to the menu on the right (make sure you enter unique IDs):
Here is the code for the buttons:
<input type="button" value="Add Item" onclick="ob_em_EasyMenu1.AddItem(document.getElementById('add_itemId').value,
document.getElementById('add_itemType').value,
document.getElementById('add_itemInnerHTML').value);"><input type="button" value="Remove Item" onclick="ob_em_EasyMenu1.RemoveItem(document.getElementById('remove_itemId').value);">
Se also
how to remove all the menu items.