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.
You need to access the nodes with
getElementById()To be a little more cautious, you can first verify that the node exists: