[thelist] DOM list elements only within another element

Simon Perry thelist at si-designs.co.uk
Fri Jul 2 10:56:01 CDT 2004


RUST Randal wrote:

>Simon Perry wrote:
>
>  
>
>>_I want to apply some behaviors to one set of elements within my page 
>>but not any others. As an example imagine the following;
>>    
>>
>
>  
>
>><div id="navcontainer">
>><ul>
>><li><a href="">home</a></li>
>><li><a href="">products</a></li>
>><li><a href="">help</a></li>
>></ul>
>></div>
>>    
>>
>
>var par=document.getElementById('navcontainer');
>var kids=par.getElementsByTagName('a');
>
>for(var i=0; i<kids.length; i++){
>	//apply your behaviors here
>	}
>
>i did not test this out, but i think it's what you are looking for.
>
>  
>
Spot on thank you Randal, I knew there should be an easy way but my 
brain had decided it was Friday afternoon and wasn't feeling helpful.

I ended up with the following;

var par=document.getElementById('navcontainer');
var alist=par.getElementsByTagName('a');
for (i=0;i<alist.length;i++){
  if(alist[i].parentNode.nodeName=="LI"){
     alist[i].onmouseover=function() {showChild(this)};
                                                                }
                                          }


More information about the thelist mailing list