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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:48:11+00:00 2026-06-09T04:48:11+00:00

Why we use root node. In below given function they use root node function.

  • 0

Why we use root node. In below given function they use root node function. I want to understand this function also what is meaning of ‘!rootNode’.

 function getElementsByClassName(cn, rootNode) {
  if (!rootNode) {
    rootNode = document;
  } 
  for (var r=[], e=rootNode.getElementsByTagName('*'), i=e.length; i--;) {
    if ((' '+e[i].className+' ').indexOf(' '+cn+' ')>-1) {
      r.push(e[i]); 
    }
  }
  return r;  
}
  • 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-09T04:48:13+00:00Added an answer on June 9, 2026 at 4:48 am

    In your example, rootNode is the HTML element from which to start recursively searching the hierarchical DOM tree (which is how the web page is represented in JavaScript) for elements with class name cn.

    This allows the caller of your function to specify from where they want to search for elements with class name cn. If the caller does not specify rootNode the function just returns every element in the entire web page with class name cn.

    The array r=[] is initialised as an empty array into which the elements that are found get added (using push).

    i-- is used because the for loop starts at i=e.length – the function goes through the elements returned by getElementsByTagName from the end of the array through to the start. The for loop evaluates the result of i-- as a boolean, exitting when i hits -1 (because on this iteration the boolean evaluation will have been done against the falue 0, because i-- post-decrements the value of i).

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

Sidebar

Related Questions

I want remove CheckBoxes where the Node.Type is 5 or 6. I use this
I use to do this on AS2 code. this.pause3Seconds = function () { trace(_global.something(_root.somthing));
What XPath do I use to query the info node in the xml below?
The query below is trying to select a child node of a given Node.
I use the ROOT C++ libraries (root.cern.ch) daily and was browsing the source when
How can I use cpanminus without root and without internet access? I am aware
I use a tabBar Controller as root controller. It has 4 tabs and each
To refer to the root of a website in asp I use an ASP
Is it good to use an autoloader that load root/app/model/test.php when trying to use
I'm trying to use basic .htaccess authentication in a subdirectory of the root where

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.