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 7054975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:41:32+00:00 2026-05-28T03:41:32+00:00

<div id=parent> <div id=child> some-value </div> </div> how do I get some-value? I tried

  • 0
<div id="parent">
    <div id="child">
        some-value
    </div>
</div>

how do I get “some-value”?
I tried

var parent = document.getElementById("parent");
var child = parent.childNodes[0];
var childval = child.value;
document.getElementById("output").innerHTML=childval;

it outputs “undefined”.

  • 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-28T03:41:33+00:00Added an answer on May 28, 2026 at 3:41 am

    The value property only exists for form elements. If you want to get the content of any other elements, you can either use innerHTML [MDN] to get the content as HTML string, or textContent [MDN] resp. innerText [MSDN] to only get the text content without HTML tags.

    childNodes [MDN] returns all child nodes, not only element nodes. That means, it also contains text nodes for example. The line break you have after <div id="parent"> is a text node as well. Hence, parent.childNodes[0] returns the text node which consists only of a line break.

    If you want to get the first element node, you can either use children [MDN] (see browser compatibility), or iterate over the child nodes, testing what kind of node each of them is. 1 indicates an element node, 3 a text node:

    var child = parent.firstChild;
    
    while(child && child.nodeType !== 1) {
        child = child.nextSibling;
    }
    

    There are also other ways to retrieve elements, e.g. with getElementsByTagName [MDN].

    Or in your case, you can just use getElementById [MDN] to get a reference to both of the elements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating some elements in javascript like so: var parent = document.createElement('div'); parent.setAttribute('id',
I have this html: <div class=foo parent> <div class=child></div> </div> with some css: .foo{
I have a parent/child divs coded as; <div class=classes scrollable> <div class=items> ....Some content
Consider my parent div is parentDiv and it contains five child divs <div id=parentDiv>
i use a parent div with three child divs , <div id=parentDiv> <div id=PagerUp
My HTML: <div id="parent"> <div id="child">cx</div> </div> When I use jQuery $('#parent').mouseout(function(){ //something here
I have a div with border-radius set to some value (let's say 10px), and
I have the following DIV structure: <div id=parent> <div id=child></div> <div id=child2></div> </div> I
I cannot seem to get hold of the parent varible from the child template,
How can I make a child div the width of the parent div when

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.