Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #19462

Re: How do I use getElementById in my situation

From "Jukka K. Korpela" <jkorpela@cs.tut.fi>
Newsgroups comp.lang.javascript
Subject Re: How do I use getElementById in my situation
Date 2013-04-25 12:19 +0300
Organization A noiseless patient Spider
Message-ID <klas9o$idf$1@dont-email.me> (permalink)
References <klar57$cfi$1@dont-email.me>

Show all headers | View raw


2013-04-25 12:00, Tony wrote:

> I have a for loop from 0 to 8 and I want to fetch the DOM element id
> that is called elem0, elem1, elem2, elem3, elem4 , elem5, elem6, elem7,
> elem8 like this
> for (var i = 0; i < antalColumner; i++) //0 - 7
> {
>   var item = "elem" + i;
>    elem = document.getElementById(item);
> }
>
> I must make the getElementById to understand that I want "elem0" and
> "elem1" and so on

So what is the problem? That seems to be what you are doing here. You 
are not using the value of the variable elem for anything, but that's a 
different issue.

On the other hand, if this is about processing a table, as the variable 
name antalColumner suggests, you could just traverse the table row by 
row and cell by cell, without needing id attributes.

-- 
Yucca, http://www.cs.tut.fi/~jkorpela/

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How do I use getElementById in my situation "Tony" <tony.johansson@inport.com> - 2013-04-25 11:00 +0200
  Re: How do I use getElementById in my situation "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2013-04-25 12:19 +0300
    Re: How do I use getElementById in my situation "Tony" <tony.johansson@inport.com> - 2013-04-25 11:29 +0200
      Re: How do I use getElementById in my situation "Tony" <tony.johansson@inport.com> - 2013-04-25 11:32 +0200
      Re: How do I use getElementById in my situation "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2013-04-25 12:35 +0300

csiph-web