[thelist] DOM: previousSibling and LI tags

VOLKAN ÖZÇELİK volkan.ozcelik at gmail.com
Thu Jan 19 15:58:11 CST 2006


To be on the safe side, you can sweep all empty text nodes of interest
before navigating through the node tree.

sample code:

var _this=_DOMManager.prototype;
function _DOMManager(){}

_this.sweep=function(obj){
	if(!obj)obj=document;
	var children=obj.childNodes;

	for(var j=0;j<children.length;j++){
		//if node is a text node and it conists of only whitespace
		if(children[j].nodeType==3&&/^\s*$/.test(children[j].nodeValue))
			children[j].parentNode.removeChild(children[j]);

		if(children[j])this.sweep(children[j]);
	}
};
var DOMManager=new DOMManager();

And after setting all these up. Simply sweep the element preferably at
window load.

window.onload=function(){
	DOMManager.sweep( document.getElementById("IDOfMyList") );
};

...

Though it's debatable, whether modifying the node tree is a good option or not.

HTH,
--
Volkan Ozcelik
+>Yep! I'm blogging! : http://www.volkanozcelik.com/volkanozcelik/blog/
+> My projects/studies/trials/errors : http://www.sarmal.com/



More information about the thelist mailing list