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

  • Home
  • SEARCH
  • 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 496185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:39:44+00:00 2026-05-13T05:39:44+00:00

Im working on a HTML test page with a simple grid that has red

  • 0

Im working on a HTML test page with a simple grid that has red or blue squares. If you click a red square it should be blue, if you click a blue square it should change to red. Sounds easy.

I have it set up so there are rows with id’s r + rownum. In my testfile i just have 2 rows: r1 and r2. Each row has the same number of children (right now 11). But when I do this:

var row = document.getElementById("r1");
alert("child count: " + row.childNodes.length);

I get 23. I get 23 for both rows. This is causing problems where wrong box gets its background changed and sometimes nothing changes. I’ll post my html and javascript, its pretty straightforward.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <style type="text/css">
      div.permissiongrid { width: 780px; }
      div.row { display: block; width: 780px; }
      span.type { width: 55px; padding: 5px; height: 55px; display: block; float: left; border-top: 1px solid #000000; border-bottom: 1px solid #000000; border-right: 1px solid #000000; }
      span.yes { background: red; }
      span.no { background: blue; }
      span.leftborder { border-left: 1px solid #000000; }
      span.num { text-indent: 1.5em; line-height: 4em; }
      p { margin: 0px; padding: 0px; }
    </style>
    <script type="text/javascript">
      function change(rownum, field)
      {
          var row = document.getElementById("r" + rownum);
          var box = row.childNodes[field];
          alert("clicked inside element with id: r" + rownum + " has child count: " + row.childNodes.length);
          if(box.className == "type no")
             box.className = "type yes";
          else
             box.className = "type no";
      }
    </script>
    <title>grid test</title>
  </head>
  <body>
      <div class="permissiongrid">
        <div class="row">
          <span class="type leftborder">Level</span>
          <span class="type">Edit Permiss-<br />ions</span>
          <span class="type">Create Accout</span>
          <span class="type">Edit Account</span>
          <span class="type">Delete Account</span>
          <span class="type">Create Page</span>
          <span class="type">Edit Page</span>
          <span class="type">Delete Page</span>
          <span class="type">Create Category</span>
          <span class="type">Edit Category</span>
          <span class="type">Delete Category</span>
        </div>
        <div class="row" id="r1">
          <span class="type leftborder num">0</span>
          <span class="type no" onclick="change(1, 1)">a</span>
          <span class="type yes" onclick="change(1, 2)">b</span>
          <span class="type yes" onclick="change(1, 3)">c</span>
          <span class="type yes" onclick="change(1, 4)">d</span>
          <span class="type yes" onclick="change(1, 5)">e</span>
          <span class="type yes" onclick="change(1, 6)">f</span>
          <span class="type yes" onclick="change(1, 7)">g</span>
          <span class="type yes" onclick="change(1, 8)">h</span>
          <span class="type yes" onclick="change(1, 9)">i</span>
          <span class="type yes" onclick="change(1, 10)">j</span>
        </div>
        <div class="row" id="r2">
          <span class="type leftborder num">1</span>
          <span class="type no" onclick="change(2, 1)">a</span>
          <span class="type no" onclick="change(2, 2)">b</span>
          <span class="type no" onclick="change(2, 3)">c</span>
          <span class="type no" onclick="change(2, 4)">d</span>
          <span class="type no" onclick="change(2, 5)">e</span>
          <span class="type no" onclick="change(2, 6)">f</span>
          <span class="type no" onclick="change(2, 7)">g</span>
          <span class="type no" onclick="change(2, 8)">h</span>
          <span class="type no" onclick="change(2, 9)">i</span>
          <span class="type no" onclick="change(2, 10)">j</span>
        </div>
      </div>
  </body>
</html>
  • 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-13T05:39:45+00:00Added an answer on May 13, 2026 at 5:39 am

    Whitespace is also a childNode. You’ll have to check nodeType

    Rather than fetching all childNodes, you want to do row.getElementsByTagName('span')

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

Sidebar

Ask A Question

Stats

  • Questions 359k
  • Answers 359k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would separate it into two for-loops--one for when flag… May 14, 2026 at 2:22 pm
  • Editorial Team
    Editorial Team added an answer In the Projects window, display the context menu without selecting… May 14, 2026 at 2:22 pm
  • Editorial Team
    Editorial Team added an answer Here are the parameters for MSBuild 3.5 Append : If… May 14, 2026 at 2:22 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.