Hello there. I have created a site using an unordered list but am having some problems with actually selecting both the li and the a tag at the same time. Its a little hard to explain but i have an example on my site:
(click on FURNITURE and then METHERINGHAM) You will notice that each clicking on each li expands some text below it and also links to a html page containing images in the right frame. My problem is that it is possible to expand the li without engaging the a tag if you click just between the li items.
I would like to make it impossible to expand the list without engaging the a tag.
I hope this makes sense, but i think that its a javascript problem?
Any help is greatly appreciated... i really am stuck and dont know alot about javascript, so please explain simply to me.
Many thanks
Ringo
(click on FURNITURE and then METHERINGHAM) You will notice that each clicking on each li expands some text below it and also links to a html page containing images in the right frame. My problem is that it is possible to expand the li without engaging the a tag if you click just between the li items.
I would like to make it impossible to expand the list without engaging the a tag.
I hope this makes sense, but i think that its a javascript problem?
Any help is greatly appreciated... i really am stuck and dont know alot about javascript, so please explain simply to me.
Many thanks
Ringo
Code:
var dMenu = (function(){
var menu;
function parentLi(el) {
do {
if (el.tagName.toLowerCase() == 'li') return el
} while (el = el.parentNode)
}
function openParentUls(el) {
while (el != menu) {
if (el.tagName.toLowerCase() == 'ul') el.style.display = '';
el = el.parentNode;
}
}
function closeAll(el) {
var el = el || menu;
var uls = el.getElementsByTagName('ul');
var i = uls.length;
while(i--){uls[i].style.display = 'none';}
}
return {
init: function (id) {
if (!document.getElementsByTagName ||
!document.getElementById ) {
return;
}
menu = document.getElementById(id);
if (menu) {
this.closeAll(menu);
var uls = menu.getElementsByTagName('ul');
var i = uls.length;
while (i--) {
parentLi(uls[i]).onclick = this.doClick;
}
}
},
closeAll: function (el) {
closeAll(el);
},
doClick: function(e) {
var e = e || window.event;
var tgt = e.target || e.srcElement;
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
while (tgt != this) {
if (tgt.tagName.toLowerCase() == 'ul') return;
tgt = tgt.parentNode;
}
var firstUl = this.getElementsByTagName('ul')[0];
var firstUlDisplay = firstUl.style.display;
closeAll(menu);
openParentUls(this);
firstUl.style.display = ('none' == firstUlDisplay)? '' : 'none';
}
}
})();