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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:29:25+00:00 2026-06-17T18:29:25+00:00

I have combined the getElementsByTagName and getAttribute methods to get the title attribute of

  • 0

I have combined the getElementsByTagName and getAttribute methods to get the title attribute of every paragraph element in the document. Here is the code:

var paras = document.getElementsByTagName('p');
for (i = 0; i < paras.length; i++) {
    console.log(paras[i].getAttribute('title'));
}

The line of code I am specifically need assistance with is this one:

console.log(paras[i].getAttribute('title'));

What is the [i] doing within this line of code? Is this the ‘counter’ variable that I declared in the for loop that is incrementing on each iteration? And is the [i] also representative of the index of the array that is returned by the getElementsByTagName function?

  • 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-17T18:29:26+00:00Added an answer on June 17, 2026 at 6:29 pm

    The key here is getElementsByTagName returns a NodeList.

    You are then looping over the NodeList (which can be thought of as an array) with you for loop. The value of i goes from 0 to the length of the array -1.

    So to answer your question. Yes, i is the index and when you say paras[i] you are asking for the element at index i.

    For example, given the following html:

    <body>
      <p id="a"></p>
      <p id="b"></p>
      <p id="c"></p>
    </body>
    

    If you called paras = document.getElementsByTagName("p") it would return an array with 3 elements.

    • At paras[0] would be the p with id a.

    • At paras[1] would be the p with id b.

    • At paras[2] would be the p with id c.

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

Sidebar

Related Questions

UPDATE I have combined various answers from here into a 'definitive' answer on a
I have this HTML: <html> <head> <title>Mouseenter and Click combined</title> </head> <body> <a id=linkselector
I have 3 tables and have to combined to get the required dataset as
I have 3 queries that I need combined into one. Here they are SELECT
I have combined MathJax and Markdown markup and therefore I need to replace all
What I want to do is something like this: I have enums with combined
Have anyone successfully managed to setup a combined Java/C++ project for Eclipse? What I
Scenario I have two WCF Services combined in a single App.Config file. I can't
I have a MySQL (5.0) table with 3 rows which are considered a combined
The Dutch and German language do have words that can be combined to new

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.