Ah I see the problem now. When you call anylinkmenu.init("menuanchorclass") again, it assigns duplicate event handlers to the anchor link and drop down menu, resulting in the "immediately disappear" issue you described.
Instead of calling anylinkmenu.init("menuanchorclass") again after you've updated the menu contents (Anylink JS Menu version), what you can do is modify anylinkmenu.js slightly so certain measurements are not cached. Use the below modified .js file, then, check out the below full HTML to see an example of adding a new menu item to the drop down menu:
Code:
<link rel="stylesheet" type="text/css" href="anylinkmenu.css" />
<script type="text/javascript" src="menucontents.js"></script>
<script type="text/javascript" src="anylinkmenu.js">
/***********************************************
* AnyLink JS Drop Down Menu v2.0- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Project Page at http://www.dynamicdrive.com/dynamicindex1/dropmenuindex.htm for full source code
***********************************************/
</script>
<body>
<!--1st anchor link-->
<p><a href="http://www.dynamicdrive.com" class="menuanchorclass" rel="anylinkmenu1">Default Example</a></p>
<a href="javascript:additem('anylinkmenu1', anylinkmenu1.items, ['Slashdot', 'http://www.slashdot.org'])">Add new item</a>
<script type="text/javascript">
//anylinkmenu.init("menu_anchors_class") //call this function at the very *end* of the document!
anylinkmenu.init("menuanchorclass")
function additem(dropmenuid, arr, el){
arr.push(el) //add new menu item content to menu array
var menuid=document.getElementById(dropmenuid)._internalID
var anchorobj=anylinkmenu.menusmap[menuid].anchorobj //references anchor link
var dropmenu=anylinkmenu.menusmap[menuid].dropmenu //references drop down menu
dropmenu.innerHTML=anylinkmenu.getmenuHTML(window[dropmenuid]) //repopulate drop down menu with updated contents
}
</script>
Bookmarks