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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:30:02+00:00 2026-06-09T23:30:02+00:00

Why when i log the tagName of all the nodes in a specific node

  • 0

Why when i log the tagName of all the nodes in a specific node list it gives me this repeating undefined feedback ?

This is the part of the code i’m extracting nodes from :

index.html

<form name="contactForm" id="contactForm">
    <div id="textInfo">
        <ul>    
            <li>            
                <label for="firstName"  class="mainLabel">First Name : </label>
                <input type="text" name="firstName" id="firstName"/>
                <span>This must be filled</span>
            </li>    
            <li>    
                <label for="lastName"  class="mainLabel">Last Name : </label>
                <input type="text" name="lastName" id="lastName"></input>
                <span>This must be filled</span>
            </li>    
            <li>    
                <label for="email"  class="mainLabel">E-mail : </label>
                <input type="email" name="email" id="email"></input>
                <span>This must be filled</span>
            </li>                            
        </ul>
    </div>​

script.js

var myForm = document.forms["contactForm"];
eventUtil.add(myForm, "submit" , function(evt){
        var firstName = myForm.elements["firstName"];

        if(firstName.value == ""){      
            for(i=0; i < firstName.parentNode.childNodes.length ; i++){
                console.log("childNodes[" + i + "]: " + firstName.parentNode.childNodes[i].tagName);
            }
            eventUtil.preventDefault(evt);
        }
    });

and the output is :

childNodes[0]: undefined
childNodes[1]: LABEL
childNodes[2]: undefined
childNodes[3]: INPUT
childNodes[4]: undefined
childNodes[5]: SPAN
childNodes[6]: undefined

Why does it give me that undefined output repeatedly ?

  • 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-09T23:30:03+00:00Added an answer on June 9, 2026 at 11:30 pm
    for(i=0; i < firstName.parentNode.childNodes.length ; i++){
        var currNode=firstName.parentNode.childNodes[i];
        if(currNode.nodeType==1){
            console.log("childNodes[" + i + "]: " + currNode.tagName);
        }                
    }
    

    you can check nodeType (Node.ELEMENT_NODE == 1) to select Element only.

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

Sidebar

Related Questions

I have this jQuery code: $('*').mouseover(function() { $('#log').text($(this)[0].tagName); }); And In my page, I
Can anyone tell me why this code would throw an undefined is not a
I've got this code in PHP5 <?php function debug_log($log) { echo $log; } //
http://hopscriber.com/log.php this [{uname:faith},{uname:losh},{uname:loshi},{uname:test}] i want to get it to the list view but i
I'm running the following code to trace the tagName of every control that gets
Here's my CoffeeScript code: $(document).ready -> SearchView = Backbone.View.extend tagName: form className: search events:
I am assuming this is either a bug in my code or an undocumented
I have the following code where i'm trying to get the c:CreationDate nodes: value
My log file in SQL Server used up all the space on my disk.
The following code returns UpperCase text of the tagName. I want the original case.

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.