JavaScript: toggle visibility of an aunt node

Intro

What is an aunt?
It is easy. If you have nested HTML elements, especially <div> nodes, then in a nested environment where a node has a parent node and a grand parent node, the aunt of an node is a node which is at the same hierarchy as its parent node.
Take the following example:
node's grand parent
node's parent
node

node's aunt
Idea
The idea was to be able to toggle in an 'grandparent parent aunt node' structure the visibility of the aunt section. Therefore toggleAunt has been created.

Example

See below to the Code section and click to retract/expand

Corresponding code

%begin html%
toggleAunt.js: JavaScript script for debugging Click to retract Click to retract ...

Auntie's area

%end%

Syntax

Code

toggleAunt.js: JavaScript script for debugging Click to retract Click to retract ...
%begin javascript%

/* * toggleAunt.js * function for setting the visibility of an 'aunt' node, where * 'aunt' is an element in the node tree hierarchy which is * on the same level as the nodes parent * * Author: P.Zumbruch, P.Zumbruch@gsi.de * Date: 05 Sep 2007 * Last change: 13 Sep 2007 * */

function toggleAunt(obj,name,value) { /* toggleAunt(obj, name, value): toggles the visibility of each 'aunt' node which title is 'name' between 'none' and 'value' where aunt is relative to the object 'obj'

argument(s): obj : object reference name : title of the aunt node(s)
value
style display option
*/

var pa = obj.parentNode; node = pa; var index = 0; while (node = null) { index++; if ( node.title == name ) { if ( node.style.display == 'none') { node.style.display = value; } else { node.style.display = 'none'; } } node = node.nextSibling; } } %end%

-- PeterZumbruch - 14 Sep 2007
Topic attachments
I Attachment Action Size Date Who Comment
toggleAunt.jsjs toggleAunt.js manage 0.9 K 2007-09-14 - 14:41 PeterZumbruch JavaScript: toggleAunt.js
Topic revision: r4 - 2007-09-14, PeterZumbruch
 
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding GSI Wiki? Send feedback
Imprint (in German)
Privacy Policy (in German)