[thelist] DOM: previousSibling and LI tags

ben morrison morrison.ben at gmail.com
Fri Jan 20 04:08:28 CST 2006


On 1/19/06, VOLKAN ÖZÇELİK <volkan.ozcelik at gmail.com> wrote:
> 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.

Phew, thats a lot to take in, haven't seen sweep() before. In my
scenario the LI elements actually have text elements so I don't think
that would work for me - or maybe i'm just confused by the way firefox
and explorer handle them differently.

thanks, ben.


More information about the thelist mailing list