Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • 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!

*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?

Get all child elements within a DIV?

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?


RE: Get all child elements within a DIV?


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.


RE: Get all child elements within a DIV?

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 <.

RE: Get all child elements within a DIV?


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


RE: Get all child elements within a DIV?

Yeah, I really didn't think using 'id' will cause it to error, however, it causes bad practice and possible interference later on.

monkeysnake <.

RE: Get all child elements within a DIV?

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 :)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

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!


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