Jump to content


Photo

Javascript getelementbyid inside other id


  • Please log in to reply
4 replies to this topic

#1 dotbart

dotbart

    Young Padawan

  • Members
  • Pip
  • 141 posts
  • Gender:Male
  • Location:Diepenbeek
  • Interests:Webdesign, Webdeveloppement, DJ, ...

Posted 20 January 2008 - 09:56 AM

Hi,

Is there a way to select an ID inside another ID
e.g.

<div id="div_one">
<a href="test.html" id="link">Test 1</a>
</div>
<div id="div_two">
<a href="test2.html id="link">Test 2</a>
</div>

As you can see both links have the same ID but can you still select them seperatly with document.getElementById(...)?



Bart

#2 Friiks

Friiks

    Young Padawan

  • Validating
  • Pip
  • 56 posts
  • Gender:Not Telling

Posted 20 January 2008 - 10:02 AM

I don't think you can because id's have to be unique.
I'm not too sure though.

#3 Matthew.

Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 20 January 2008 - 10:59 AM

I don't think you can because id's have to be unique.
I'm not too sure though.


Correct :)

Element id attributes are unique just like pretty much any other id, its an identifier so there can't be duplicates.

#4 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 20 January 2008 - 02:14 PM

http://www.pixel2lif...p...st&p=243857

Change the id's to a class, then loop through the elements in the divs using getElementsByTagName() and check the className's.

#5 dotbart

dotbart

    Young Padawan

  • Members
  • Pip
  • 141 posts
  • Gender:Male
  • Location:Diepenbeek
  • Interests:Webdesign, Webdeveloppement, DJ, ...

Posted 20 January 2008 - 05:38 PM

Ok, thanks for replies!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users