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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:59:23+00:00 2026-06-15T19:59:23+00:00

This is a simple page that demonstrates some basic functionality of d3. I made

  • 0

This is a simple page that demonstrates some basic functionality of d3. I made a dataset var dataset = [3,1,4,1,5]; and would like to output it as well as some paragraphs. The data is appearing, but after the body! Strange …

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title> demo project</title>
    <script type="text/javascript" src="d3/d3.v2.js"></script>
</head>
<body>

    <script type="text/javascript">
        d3.select("body").append("p").text("hello!");
        d3.select("p").append("text").text(" hello!!");
        d3.select("body").append("p").text("hello2!");
        d3.select("p:nth-child(3)").append("text").text(" hello2!!");
        var dataset = [3,1,4,1,5];
        d3.select("p:nth-child(3n+1)")
            .data(dataset)
            .enter()
            .append("p")
            .text(function(d) { return d; });
        d3.select("p:nth-child(7n + 1)").append("text").text("hello againss?");
    </script>

</body>
</html>

the page looks like this:

enter image description here

and the DOM looks like this (note the data shows up after the body close tag):

enter image description here

Also note that the line d3.select(“p:nth-child(7n + 1)”).append(“text”).text(“hello againss?”); was intended to be printed after all my data, but it does not show up.

  • 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-06-15T19:59:24+00:00Added an answer on June 15, 2026 at 7:59 pm

    The short answer is that in your particular case the enter() selection’s parentNode is the document (and not the body).

    Let’s take a simple example to see what an enter() selection looks like. Assuming we have a document with a body without any p elements.

    var ps = d3.select("body").selectAll("p")
        .data([0, 1, 2]);
    

    Since no p elements existed yet, the enter() selection will have three elements. Let’s inspect the enter selection:

    ps.enter()

    You see that the inner array has a property named parentNode. When you add new elements using selection.append() or selection.insert() the new elements will be created as children of that parentNode.

    So, inspecting ps.enter()[0].parentNode will reveal the body element. It now becomes clear that, in a data join, the selection before the selectAll specifies the parentNode; in the above case that was d3.select("body").

    What if we had omitted the select(“body”) part in the data join?

    // example of bad data join
    var ps2 = d3.selectAll("p")
        .data([0, 1, 2]);
    

    It turns out that in this case ps2.enter()[0].parentNode is the #document! That means that if you add elements using this enter() selection, they will become the document’s direct children. The append method will add them to the end of the document; i.e. after the body.

    The last case is basically what you’ve encountered. Your data join and enter expression is not correct; it should follow this pattern:

    d3.select(parent).selectAll(element)
        .data(data)
      .enter().append(element);
    

    BTW, there is no HTML text element. So, append("text") doesn’t seem meaningful.

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

Sidebar

Related Questions

If I have a simple web page and script that looks like this: <body>
This is bugging me ... I have a simple HTML page that has a
I have an Asp .net page like this simple one http://issamsoft.com/app2/page1.aspx and I want
Suppose I get, on a page, this simple html/script : <a id=hey href=#>try</a> var
I have simple HTML page with svg like this: <div id=plan> <svg xmlns=http://www.w3.org/2000/svg version=1.1>
Consider this simple class that demonstrates RAII in C++ (From the top of my
please consider this scenario: we have two web page. a simple page that contains
Simple question. I try to make simple page that use one key. Is this
I have an extremely simple page that isn't displaying properly in IE6. In this
Look at this simple page: <!DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN http://www.w3.org/TR/html4/loose.dtd> <html>

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.