This one nagivates through DOM, without reference to ids
<html>
<head>
<title>GetChildByTagName Document</title>
</head>
<body>
<script language="javascript">
function getChildByTagName (obj, tagName) {
if (!obj) { return null; }
for (var ix=0; ix < obj.childNodes.length; ix++) {
var cObj = obj.childNodes[ix];
if (!cObj || !cObj.tagName) { continue; }
if (cObj.tagName.match(tagNam
return cObj;
}
if (cObj.childNodes.length) {
cObj = getChildByTagName(cObj, tagName);
if (cObj && cObj.tagName.match(getChil
}
}
}
function getParent (src, tagName) {
while (src.parentNode != null) {
if (src.parentNode.tagName == tagName) {
return src.parentNode;
}
src = src.parentNode;
}
return src;
}
function menu_toggle(aObj) {
var pObj= getParent(aObj, 'LI');
if (pObj) {
var uObj =getChildByTagName (pObj, 'UL');
if (uObj) { alert (uObj.innerHTML); }
}
retun (false);
}
</script>
<ul>
<li><a href="#" title="Toggle" onclick="return menu_toggle(this);">1</a>
<ul id="one">
<li>1a</li>
<li>1b</li>
<li>1c</li>
<li>1d</li>
</ul>
</li>
<li><a href="#" title="Toggle" onclick="return menu_toggle(this);">2</a>
<ul id="two">
<li>2a</li>
<li>2b</li>
<li>2c</li>
</ul>
</li>
</ul>
</body>
</html>
Main Topics
Browse All Topics





by: sam85281Posted on 2006-03-31 at 22:53:05ID: 16348595
Not really clear on all your questions/what you're asking for but best way to pass reference to the function is:
title="Toggle" onclick="menu_toggle(1);"> 1</a>
<a href="javascript:void(0);"
Would help to see your toggle_menu() function but rebuild it something like:
function menu_toggle (linkID) {
if (linkID == 1) {
// do this
} else if (linkID == 2) {
//do this
}
}
If I'm missing your point altogether...please provide more details of whay you're trying to accomplish.
-Sam