initer
initer

Reputation: 23

Accessing objects within objects in the DOM?

How do I accesss the div the id 950 in the example below using javascript?

<ins>
<div>
<div>
<div id="950"></div>
</div>
</div>
</ins>

A simple getelementbyid doesn't work...

document.getElementById('950');

Upvotes: 1

Views: 61

Answers (4)

Praveen Prasad
Praveen Prasad

Reputation: 32117

make sure you are calling document.getElementById('950'); after dom elements are created.

Try shifting your code at the bottom of the page!!

Upvotes: 1

silverstrike
silverstrike

Reputation: 522

The ID attribute should start with a letter. Perhapse that is what causing JS parser to return an error.

Upvotes: 1

user882255
user882255

Reputation:

"id" can't begin with a number. See this: http://www.w3.org/TR/html4/types.html#type-name

Everything else is ok.

Upvotes: 1

Justin Ethier
Justin Ethier

Reputation: 134177

getElementById always returns the requested element, without regard nesting level. Something else must be going on here. For example, what is the purpose of the ins tag in your example?

Upvotes: 2

Related Questions