Tuesday, 20 August 2013

How to search within an array?

How to search within an array?

I have this function that it suppose to get all the from the page, I'm
trying to all all the anchors within those links, but I keep getting
Object [object HTMLAnchorElement] has no method errors, I've tried using
split, search and indexOf, but everything gives mes the same error, what
am I doing wrong?
I know I'm getting all the tags, the first alert returns their total
number. Here's what I have:
// get all the link tags from the page
var a = document.getElementsByTagName('a');
//alert(a.length)
for (var i = 0; i < a.length; i++)
{
// check which links have an anchor within them
if(a[i].search("#") > 1)
{
alert("yes");
}
else
{
alert("no");
}
}

No comments:

Post a Comment