CODE SNIPPETS AND HINTS
|
|
As we all should know there is more than one way to skin a cat... but... If you want to share or have me share some code snippets out of the public forum... please do so here. |
|
|
Here are some functions, some of which I've made and some of which I've modified.
// Create by avg, modified by me
function create(a,b) {
var ret=document.createElement(a);
if(b) for(var prop in b) {
if(/^on/.test(prop))
ret.addEventListener(prop.substring(2),b[prop],false);
else if(prop=="kids") {
prop=b[prop];
for(var i=0;i<prop.length;i++)
ret.appendChild(prop[i]);
}
else if(prop=="style") ret.setAttribute("style", b[prop]);
else
ret[prop]=b[prop];
}
return ret;
}// XPath by JoeSimmons
function xp(exp, t, n) {
return t==9 ? document.evaluate(exp||"//body",n||document,null,9,null).singleNodeValue : document.evaluate(exp||"//body",n||document,null,t||6,null);
}// deleteAll(array) by JoeSimmons
function deleteAll(array) {
if(array.snapshotItem) for(var i=array.snapshotLength-1; i>=0; i--) array.snapshotItem(i).parentNode.removeChild(array.snapshotItem(i));
else if(!array.snapshotItem) for(var i=array.length-1; i>=0; i--) array[i].parentNode.removeChild(array[i]);
}
|