[Javascript] Replace element with another element on click

Shawn Milo shawn.milo at gmail.com
Wed Mar 23 07:52:20 CST 2005

In this case, I like to put each object in a DIV, and play with the visibility.


Use this:

theObject.style.display = "none";
theObject.style.display = "block";

Do whatever on the onchange() of the checkbox.

Declare one of the objects like this in the HTML:
<div id=weeklyStart style="display:none;">
put object here

That way, one will be invisible by default.

I have used this to have a retail sales report which has
monthly, weekly, and daily views all on one page.  When you select
'weekly,' for example, it makes the start/end week options appear, 
and the month or day boxes disappear. You get the idea.


On Wed, 23 Mar 2005 00:43:38 -0600, Peter Brunone <peter at brunone.com> wrote:
>         Well, the nice IE way is to use the outerHTML property and just
> gut the whole thing (it's pretty fast, too).
>         If that's not an option, you could have both elements at the
> same point in your code and alternately set their height and width to
> 0px (I tried display:none but Netscape 7 doesn't support it).
> Cheers,
> Peter
> -----Original Message-----
> From: javascript-bounces at LaTech.edu On Behalf Of judah
> I was curious how to replace a element with another element when the
> user clicks a checkbox. If checkbox is enabled then replace element A
> with B (erase A). If checkbox is unchecked then replace element B with A
> (erase B).
> Best Regards,
> Judah
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript

Voicemail any time at:

More information about the Javascript mailing list