sorry i actually ended up finishing this before you posted:
findDDtags : function(obj) {
pNode = obj.parentNode; //the DT tag
//find the existing DT tag
for (i=0;i < pNode.parentNode.childNode
curTag = pNode.parentNode.childNode
if (curTag == pNode) {
var dtNum = i;
}
}
//find the number of the last DD child node from the existing DT tag
for (j=dtNum;j < pNode.parentNode.childNode
curTag = pNode.parentNode.childNode
curSibling = pNode.parentNode.childNode
//make sure the current tag has a sibling
if (curSibling != null) {
//make sure the sibling is an actual tag, not whitespace
if (curSibling.nodeType == 1) {
if (curSibling.nodeName != "DD") {
lastDD = j;
break;
}
}
} else { //there was no sibling - this is the last tag
lastDD = j;
}
}
//toggle them
for (k=dtNum;k < lastDD;k++) {
curTag = pNode.parentNode.childNode
curSibling = pNode.parentNode.childNode
//make sure the current tag has a sibling
if (curSibling != null) {
//make sure the sibling is an actual tag, not whitespace
if (curSibling.nodeType == 1) {
if (curSibling.nodeName == "DD") {
toggle(curSibling);
}
}
}
}
}
i don't have timeto test your solution but if someone else can confirm it looks good i can give you the points.
bruno
Main Topics
Browse All Topics





by: radevoPosted on 2006-05-01 at 09:30:24ID: 16578380
This should be cross-browser workable (tested in Firefox).
ntainer" class="scrollBox-content-c ontainer">
For IE only audience, you could work with DOM node property .nextSibling instead of looping over childNodes.
<html>
<head>
<title>Toggler</title>
<script type='text/javascript'>
function toggle(button) {
for (var dt = button.parentNode; dt!=null && dt.nodeName!='DT'; dt=dt.parentNode) {}
var parent = dt.parentNode
var dt_siblings = parent.childNodes;
var node;
var do_toggle = false
var mode = '?'
var done = false
for (var i=0; i<dt_siblings.length && !done; i++) {
var node = dt_siblings[i]
if (node == dt)
do_toggle = true
else
if (node.nodeName == 'DT')
do_toggle = false
done = (mode != '?')
else
if (do_toggle && node.nodeName == 'DD') {
if (mode == '?') {
if (node.style.display == 'none')
mode = 'block'
else
mode = 'none'
}
node.style.display = mode
}
}
}
</script>
</head>
<body>
<div id="my-project-programs-co
<dl>
<dt><strong>Project Name:</strong> Star
<input type=button value="toggle" onclick="toggle(this)">
</dt>
<dd><a href="">Latest Status Report</a></dd>
<dd><a href="">Technical Overview</a></dd>
<dd class="last"><a href="">Team QA Report</a></dd>
<dt><strong>Project Name:</strong> Star
<input type=button value="toggle" onclick="toggle(this)">
</dt>
<dd><a href="">Latest Status Report</a></dd>
<dd><a href="">Technical Overview</a></dd>
<dd class="last"><a href="">Team QA Report</a></dd>
<dt><strong>Project Name:</strong> Star
<input type=button value="toggle" onclick="toggle(this)">
</dt>
<dd><a href="">Latest Status Report</a></dd>
<dd><a href="">Technical Overview</a></dd>
<dd class="last"><a href="">Team QA Report</a></dd>
<dt><strong>Project Name:</strong> Star
<input type=button value="toggle" onclick="toggle(this)">
</dt>
<dd><a href="">Latest Status Report</a></dd>
<dd><a href="">Technical Overview</a></dd>
<dd class="last"><a href="">Team QA Report</a></dd>
</dl>
</div>
</body>
</html>