Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
170
rated 0 times [  177] [ 7]  / answers: 1 / hits: 18142  / 16 Years ago, fri, march 6, 2009, 12:00:00

How can I refer to a nested div by id when it has the same id as a div nested in a similarly named div



eg



<div id=obj1>
<div id=Meta>
<meta></meta>
</div>
</div>

<div id=obj2>
<div id=Meta>
<meta></meta>
</div>
</div>


I want to get the innerHTML of meta



document.getElementById('obj1').getElementById('Meta').getElementsByTagName('meta')


doesn't work


More From » html

 Answers
34

IDs should only be used when there is one of that item on the page, be it a SPAN, DIV or whatever. CLASS is what you should use for when you may have a repeating element.



Code there doesn't work because you're referring to an element by unique ID, but have more than one on the page.


[#99886] Friday, February 27, 2009, 16 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
gageherberth

Total Points: 249
Total Questions: 115
Total Answers: 119

Location: Liechtenstein
Member since Sun, Sep 12, 2021
3 Years ago
gageherberth questions
;