Smart questions
Smart answers
Smart people
Join Tek-Tips Forums

Member Login

Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Get all child elements within a DIV?

ericse (Programmer) (OP)
14 Jun 07 11:34
Hey guys-

I can't seem to do this. Everything I try fails.

I have the ID of the Div... and I create controls dynamically within that div. I want to change the styles of those elements within the div.

How can I do this?

I've tried: var children = document.getElementById('id').getChildren();

but it fails saying getChildren() is not a function.

.childNodes also fails. I just don't get it.

Please help?

feherke (Programmer)
14 Jun 07 11:48

childNodes must work.


var children = document.getElementById('id').childNodes;

// or

var children = document.getElementById('id').getElementsByTagName('*');
Note that there is a difference between the above two : the first returns the list of direct descendants, while the second returns a list of all descendants.


monksnake (Programmer)
14 Jun 07 11:49
I think you need to revisit this:


.childNodes also fails. I just don't get it.

Give your div a different id other than 'id'


var childNodeArray = document.getElementById('somethingOtherThanid').childNodes;

If that doesn't work, then your problem lies somewhere else.

monkeysnake <.

feherke (Programmer)
14 Jun 07 12:07

The 'id' id seems to not affect FireFox, Opera, Safari and Explorer. They all work as expected. What browser are you using ericse ?


monksnake (Programmer)
14 Jun 07 12:09
Yeah, I really didn't think using 'id' will cause it to error, however, it causes bad practice and possible interference later on.

monkeysnake <.

ericse (Programmer) (OP)
14 Jun 07 12:10
Hey guys, I wasn't actually using 'id' heh, I just used that as an example because I was lazy and didn't want to type out the *real* id.. Anyway, I got it to work using getElementsByTagName("*") so thanks for the help :)

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close