home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2008 April
/
PCWorld_2008-04_cd.bin
/
multimedia
/
mediacoder
/
MediaCoder-0.6.0.3905.exe
/
extensions
/
_include
/
domhelper.js
next >
Wrap
Text File
|
2007-02-05
|
2KB
|
100 lines
function getNextNode(node)
{
do {
node = node.nextSibling;
} while (node && node.nodeType!=1);
return node;
}
function getChildNode(node)
{
node = node.firstChild;
while (node && node.nodeType != 1) {
node = node.nextSibling;
}
return node;
}
function getLastChildNode(node)
{
node=node.lastChild;
while (node && x.nodeType!=1) {
node=node.previousSibling;
}
return node;
}
function getNodeValue(node)
{
return node.firstChild ? node.firstChild.nodeValue : null
}
function getParentNode(node)
{
return node.parentNode;
}
function getNodeByName(node, name)
{
for (; node && node.nodeName != name; node = getNextNode(node));
return node;
}
function getChildNodeValue(node, name)
{
for (node = getChildNode(node); node && node.nodeName != name; node = getNextNode(node));
return node ? getNodeValue(node) : null;
}
function getNodeByAttribute(node, name, attrname, attrvalue)
{
for (; node; node = getNextNode(node)) {
if (node.nodeName == name && node.getAttribute(attrname) == attrvalue) return node;
}
return null;
}
function addAttribute(doc, node, attrname, attrvalue)
{
var attr = doc.createAttribute(attrname);
attr.value= attrvalue;
node.setAttributeNode(attr);
return attr;
}
function addElementNode(doc, node, name)
{
var elementNode = doc.createElement(name);
node.appendChild(elementNode);
return elementNode;
}
function addTextNode(doc, node, text)
{
var textNode = doc.createTextNode(text);
node.appendChild(textNode);
return textNode;
}
function removeFirstChild(node)
{
var c = getChildNode(node);
return c?node.removeChild(c):null;
}
function removeLastChild(node)
{
var c = getLastChildNode(node);
return c?node.removeChild(c):null;
}
function removeChildren(node)
{
var c = getChildNode(node);
while(c) {
var n=getNextNode(c);
node.removeChild(c);
c=n;
}
}