Find the specific elements of the context based on the current node
Search for child elements:
Code transferred from birdhome
<SCRIPT Lanuage = "JavaScript">
Function findchildelement (element, tagname)
{
VaR isfounded = false;
VaR elements = element;
VaR result = element;
If (element. tagname = tagname)
{
Return element;
}
While (! Isfounded & elements! = NULL & result! = NULL & result. tagname! = Tagname)
{
Elements = elements. childnodes;
For (VAR I = 0; elements! = NULL & I <elements. length; I ++)
{
Result = elements. item (I );
VaR result2 = findchildelement (result, tagname );
If (result = NULL | result2 = NULL)
{
Continue;
}
If (result. tagname = tagname | result2.tagname = tagname)
{
If (result2.tagname = tagname)
{
Result = result2;
}
Isfounded = true;
Break;
}
}
}
If (isfounded)
{
Return result;
}
Else
{
Return NULL;
}
}
</SCRIPT>
Find parent Element
<SCRIPT Lanuage = "JavaScript">
Function findparentelement (element, tagname)
{
While (element! = NULL & element. tagname! = Tagname)
{
Element = element. parentelement;
}
If (element! = NULL & element. tagname = tagname)
{
Return element;
}
Return NULL;
}
</SCRIPT>