W3C home > Mailing lists > Public > www-dom@w3.org > April to June 2005

Re: DOM and XHMTL

From: Ray Whitmer <ray@xmission.com>
Date: Mon, 9 May 2005 07:28:28 -0600 (MDT)
To: Tommie Westling <Tommie.Westling@Tactics.Se>
cc: www-dom@w3.org
Message-ID: <Pine.LNX.4.63.0505090716490.17733@xmission.xmission.com>

On Thu, 5 May 2005, Tommie Westling wrote:

> Hi,
>
> I wonder if a can use DOM with XHMTL to do dynamic text features like
> expand and collapse?
>
> How should the code look like for this scenario:
>
> When i click on the playername it would expand like this:
>
> Playername1
> Playername2
> Playername3
>
> Playername1
> Text1
> Text2
> Text3
> Playername2
> Playername3

This is quite easy to do.  What you need to do is change the value of the
display CSS property of the element in question to make it expand or collapse.

For example:

document.getElementByID("foo").style.display="none"

to make it disappear

document.getElementByID("foo").style.display=""

to make it reappear

With standards-compliant browsers, you could use the actual display
value dictated by CSS, such as

document.getElementByID("foo").style.display="table-row"

if it is a table row you are manipulating.

but I have never found a version of IE to support this very well whereas
they all (stanedards compliant and not) support setting it to empty string
which gives you the default displayed form, even if it looks a little odd.

In the above examples, replace "foo" with the ID of the element you want to
make disappear or reappear.  There is more supporting code you need like
deciding when to make it disappear and reappear, what to do on browsers that
have disabled scripting, etc.

This particular attribute falls outside of the current DOM standard (I think it
is in the CSS Object Model, originally defined by this group but transferred to
the CSS group.

Ray
Received on Monday, 9 May 2005 13:28:57 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:13:58 GMT