Home  >  Article  >  Web Front-end  >  Implementation code for obtaining adjacent elements of the same type of an element under FF Firefox_javascript skills

Implementation code for obtaining adjacent elements of the same type of an element under FF Firefox_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:46:221216browse
Copy code The code is as follows:

// Compatible with Firefox to get the previous neighbor of the same type of a node Node
function previousSiblingSameType(node, cnode)
{
// If it is empty, return null directly
if(node.previousSibling == null)
{
return null;
}
else
{
// Continue recursion if node types are not equal
if(node.previousSibling.nodeType != cnode.nodeType)
{
return perviousSiblingSameType(node.previousSibling , cnode);
}
// If the node types are equal, return
else if(cnode.nodeType == node.previousSibling.nodeType)
{
return node.previousSibling;
}
}
}

// Compatible with Firefox to get the next adjacent node of the same type of a node
function nextSiblingSameType(node, cnode)
{
// is Empty returns null directly
if(node.nextSibling == null )
{
return null ;
}
else
{
// Continue recursion if node types are not equal
if(node.nextSibling.nodeType != cnode.nodeType)
{
return nextSiblingSameType(node.nextSibling , cnode);
}
// If the node types are equal, return
else if(cnode.nodeType == node.nextSibling.nodeType)
{
return node.nextSibling ;
}
}
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn