[thelist] RE: javascript - changing css with javascript

miinx lists at miinx.com.au
Sat Sep 28 22:54:01 CDT 2002


Dru and Cindy Sellers wrote:
> function cssMenu(obj)
> {
>   document.getElementById(" + obj + ").style.display =
> (document.getElementById(" + obj + ").style.display == 'none') ? 'block' :
> 'none';
> }
>
> however, I can not seem to find the right term to search on that explains
> how to use a variable in the getElementById() function. It seems to want a
> string in quotes in the () but if I just put (obj) it does not work.
>

that's right - it's looking for the id of the object (as a string), not
the actual object itself.

so you need to be passing the id:
    document.getElementById(obj.id).style.display

however, if you've already got your object reference, you don't need to
be using document.getElementById at all

so just this may work in your example:
    obj.style.disply

hth
karen
-------
Miinx Design & Development
e :: karen at miinx.com.au
p :: 0413.880.302
w :: www.miinx.com.au





More information about the thelist mailing list