[Javascript] GetElementByElement?

Håkan Magnusson hakan at backbase.com
Thu Mar 4 04:47:53 CST 2004


I'm not sure on what you're trying to do here, but you always have 
document.getElementsByTagName('[TAGNAME]');, which returns an array 
(nodelist) with all the [TAGNAME] elements in the document. To get the 
body element, simply do

var oBody = document.getElementsByTagName('body')[0];

Regards,
H

Simeon Willbanks wrote:

> Hello All,
> 
> I grabbed a bit of code from a dhtml kitchen tutorial.  I am trying to 
> modify it to fit my needs.  Below is the original code
> 
>     function setStyle(obj,style,value){
>         getRef(obj).style[style]= value;
>     }
>     
>     function getRef(obj){
>         return (typeof obj == "string") ?
>              document.getElementById(obj) : obj;
>     }
> 
> You can then use an onclick event to set a style by id, and it works 
> beautifully.  
> 
> <p class="link" onclick="setStyle('fixed','visibility','hidden')">Close 
> The Ad</p>
> 
> What I need to do is change and element property along with an id 
> property.  In other words, set  a div to display:none; and change the an 
> element like body: padding-bottom: 0;  
> I don’t know if a function exists like getElement?  Maybe than I could 
> write a function to recognize the body element css properties in order 
> to switch the properties?  Has anyone tired to do this before?  Any help 
> would be appreciated.
> 
> Thanks,
> Simeon
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript



More information about the Javascript mailing list