Variable Object/Element/Property Names

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Zach

    #1

    Variable Object/Element/Property Names

    How do I call an object/element/property when one or more of the names
    are defined by a variable? I want to do something like this:

    [var_window_name].document.getEl ementById("[var_id]").style.foo="b ar"

    Am I missing something obvious, or is this not possible? And if not,
    any suggested work-arounds?

    Thanks!

  • Randy Webb

    #2
    Re: Variable Object/Element/Property Names

    Zach wrote:[color=blue]
    > How do I call an object/element/property when one or more of the names
    > are defined by a variable? I want to do something like this:
    >
    > [var_window_name].document.getEl ementById("[var_id]").style.foo="b ar"[/color]

    window[var_window_name].document.getEl ementById(var_i d).style.foo.=b ar;

    How you address var_window_name depends on what var_window_name refers
    to though.
    [color=blue]
    > Am I missing something obvious, or is this not possible? And if not,
    > any suggested work-arounds?
    >
    > Thanks!
    >[/color]


    --
    Randy
    comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
    Answer:It destroys the order of the conversation
    Question: Why?
    Answer: Top-Posting.
    Question: Whats the most annoying thing on Usenet?

    Comment

    • Zach

      #3
      Re: Variable Object/Element/Property Names

      Ah, syntax. Amazing how much time I manage to waste misplacing
      various brackets and quotes. I'm blaming the documentation ;)

      Thanks for your help! That works perfectly for me.

      -Zach

      On Mon, 07 Mar 2005 04:41:15 -0500, Randy Webb
      <HikksNotAtHome @aol.com> wrote:
      [color=blue]
      >Zach wrote:[color=green]
      >> How do I call an object/element/property when one or more of the names
      >> are defined by a variable? I want to do something like this:
      >>
      >> [var_window_name].document.getEl ementById("[var_id]").style.foo="b ar"[/color]
      >
      >window[var_window_name].document.getEl ementById(var_i d).style.foo.=b ar;
      >
      >How you address var_window_name depends on what var_window_name refers
      >to though.
      >[color=green]
      >> Am I missing something obvious, or is this not possible? And if not,
      >> any suggested work-arounds?
      >>
      >> Thanks!
      >>[/color][/color]

      Comment

      Working...