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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:23:33+00:00 2026-05-26T04:23:33+00:00

I have an array as shown below which represents the ids of objects in

  • 0

I have an array as shown below which represents the ids of objects in the body of the HTML body:

var p=new Array ("p1" ,"p2" ,"p3" ,"p4" ,"p5","p6","p7","p8","p9","p10","p11" ,"p12","p13", "p14","p15","p16","p17","p18","p19","p20");

i need to iterate over those objects and retrieve their data, and i’m doing this in the following way which is not working:

for(var i=0; i<20; i++)
        {
           var price=p[i].innerHTML;
           if(price.length != 7)
           {
             alert("yes");
           }
        }

What is the correct way to do what i’m trying to do? Thanks in advance.

  • 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-26T04:23:33+00:00Added an answer on May 26, 2026 at 4:23 am

    You need to access the nodes with getElementById()

    for(var i=0; i<20; i++)
    {
       var price = document.getElementByid(p[i]).innerHTML;
       if(price.length != 7)
       {
         alert("yes");
       }
    }
    

    To be a little more cautious, you can first verify that the node exists:

    for(var i=0; i<20; i++)
    {
       var elem = document.getElementByid(p[i]);
       // Only attempt to do anything if the node exists...
       if (elem)
       {
         var price = elem.innerHTML;
         if(price.length != 7)
         {
           alert("yes");
         }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of objects which is initialized in Java as shown below:
I have an array which produces output as shown below : for($i=0; $i<$cnt; $i++)
So I have a sort of zigzag pattern, as shown below. , which is
I have multiple arrays shown below. <?php $arrLayout = array( section1 => array( wXBMCLibrary
I have a method which insert a record into a table as shown below:
I have CSV file which has timestamp in the first column as shown below
Let's say I have an unsorted array from 1 to 10, as shown below...
I have a DependencyObject in C# that is used in an array. Example shown
Let's say I have array of bytes: byte[] arr = new byte[] { 0,
I have a PHP array question regarding searching which I'm hoping some kind person

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.