Forum Moderators: open
I use the following code to expand a submenu block in a <dl> menu.
function checksubmnu(id) {
var d = document.getElementById(id);
for (var i = 1; i<=10; i++) {
if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
}
//if it exist show it
if (d) {d.style.display='block'};
}
In IE6 and netscape it works pefectly when I define the UL/LI but when I use createElement to create the choices the block shows but will not move down the rest of the menu, rather it is in the background in netscape 9. In IE is still works perfectly.
The sub is created with :
var dt = document.createElement('dt');
dt.appendChild(document.createTextNode('Menu '+mname));
var dd = document.createElement('dd');
dd.setAttribute('id','smenu'+mname);
var ul = document.createElement('ul');
var li1 = document.createElement('li');
var a = document.createElement('a');
a.setAttribute('href', '#');
a.appendChild(document.createTextNode('sub menu 3.1'));
a.onclick = function () {test()};
li1.appendChild(a);
ul.appendChild(li1);
var li2 = document.createElement('li');
var a = document.createElement('a');
a.setAttribute('href', '#');
a.appendChild(document.createTextNode('sub menu 3.2'));
a.onclick = function () {test()};
li2.appendChild(a);
ul.appendChild(li2);
dd.appendChild(ul);
dt.appendChild(dd);
dt.onclick = function () {checksubmnu(dd.id)};
document.getElementById('mmenu').appendChild(dt);