Anser,
After a long fight with DOM, its working
Javascrip code
- Code: Select all Expand view
-
- function expandCode( aTag )
- {
- var code = aTag.parentNode.nextSibling.lastChild;
-
- if( code.style.maxHeight != "none" )
- {
- aTag.innerHTML = "Collapse view";
- code.style.maxHeight = "none";
- }
- else
- {
- aTag.innerHTML = "Expand view";
- code.style.maxHeight = "200px";
- }
- }
-
A code section has this structure:
- Code: Select all Expand view
-
- <DL> // distribution list
- <DT> // distribution title
- the <a hrefs> are here
- </DT> // end of the distribution title
- <DD> // distribution description (data)
- <CODE> // here is the code, where we want to swap its style !!!
- </CODE>
- </DD>
- </DL> // end of the distribution list
-
This code is really tricky:
aTag.parentNode.nextSibling.lastChild;
1) aTag is the <a href> where we click
2) parentNode is the parent of aTag, that is, the DT (distribution title) of the DL (distribution list)
3) nextSibling is the next child, after DT, so it is DD.
4) lastChild is the only child that DD has: <code>
There we are and then we change its style