INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

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!

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?

Share

Get all child elements within a DIV?

Get all child elements within a DIV?

(OP)
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?

THanks

RE: Get all child elements within a DIV?

Hi

childNodes must work.

CODE

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.

Feherke.
http://rootshell.be/~feherke/

RE: Get all child elements within a DIV?

I think you need to revisit this:

Quote:


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

Give your div a different id other than 'id'

CODE

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?

Hi

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

Feherke.
http://rootshell.be/~feherke/

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?

(OP)
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!

Resources

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