Large

Hello, World

By Marti Last update Nov 30, 2011 — Installed 538 times.

CODE SNIPPETS AND HINTS

in
Subscribe to CODE SNIPPETS AND HINTS 2 posts, 2 voices



Marti Script's Author

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.

 
JoeSimmons Scriptwright

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]);
}

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel