Home > Web Front-end > JS Tutorial > 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
Release: 2016-05-16 17:46:22
Original
1226 people have browsed it
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 ;
}
}
}
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template