Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7164013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:59:56+00:00 2026-05-28T13:59:56+00:00

There is HTML page with contents like this. Documentation at MDN says that childNodes

  • 0

There is HTML page with contents like this.

enter image description here

Documentation at MDN says that childNodes returns a collection of child nodes of the given element which is a NodeList.

So, according to the doc, the first child for the NodeList should be <h1>PyCon Video Archive</h1>.

But, in Developer Tools (Chromium), it says the other way.

![enter image description here][2]

So, why exactly the first node is not <h1>PyCon Video Archive</h1>?
Why a text object as first element?

I would appreciate some help here.

EDIT

So, I just figured out that in Firebug (FF), the same function behaves differently.

enter image description here

My new question: Is using .childNodes() an unreliable way of accessing DOM elements?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:59:56+00:00Added an answer on May 28, 2026 at 1:59 pm

    To get the first element child, you can use…

    document.body.firstElementChild;
    

    …but older brwosers don’t support it.


    A method that has greater support is the children collection…

    document.body.children[0];
    

    …which has pretty good support but still has some holes in terms of older browsers.

    (Just double checked, and as long as you don’t support Firefox 3, and as long as you don’t include HTML code comments in the markup, using .children will be safe.)


    To ensure that you have the widest browser support, create a function…

    function firstElementChild( parent ) {
    
        var el = parent.firstChild;
        while( el && el.nodeType !== 1 )
            el = el.nextSibling;
    
        return el;
    }
    

    and use it like this…

    var h1 = firstElementChild( document.body );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page that loads an external HTML page into an iFrame. There
Is there a way to find the HTML element on the page that a
I have a page with many HTML lines like this: <ul><li><a href='a_silly_link_that_changes_each_line.php'>the_content_i_need</a></li></ul> Now as
Are there any html helpers for page navigation. eg. if i have 1000 records
Is there a way to export a simple HTML page to Word (.doc format,
Is there a way to access the page HTML source code using javascript? I
Is there a way to trigger a GridView rebind from an html markup page
On the page there are links displayed with CSS as buttons: HTML: <a class=button
Is there a page similar to JSbin where I can test HTML and CSS
The code segment is from a page called sites-catchup.html. There is a simple server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.