getAttribute("rel") has no properties

  • Thread starter christopher.secord
  • Start date
C

christopher.secord

I'm having a hard time understanding an error that I'm getting. In the
code below, I'm trying to call substring() on an attribute of an
anchor. The error I get says "getAttribute("rel") has no properties"

The reason this confuses me is that getAttribute("rel") returns a
string, so it should have all the properties and methods of a string,
right?? What am I missing here?

- chris

var AnchorArray = document.getElementsByTagName("a");

for (var i = 0; i < AnchorArray.length; i++) {

if (AnchorArray.getAttribute("rel").substring(0,5) == "other")
alert("hi there");

}
 
N

naixn

I'm having a hard time understanding an error that I'm getting. In the
code below, I'm trying to call substring() on an attribute of an
anchor. The error I get says "getAttribute("rel") has no properties"

The reason this confuses me is that getAttribute("rel") returns a
string, so it should have all the properties and methods of a string,
right?? What am I missing here?

- chris

var AnchorArray = document.getElementsByTagName("a");

for (var i = 0; i < AnchorArray.length; i++) {

if (AnchorArray.getAttribute("rel").substring(0,5) == "other")
alert("hi there");

}


The error you get (getAttribure('rel') has no properties), means that
in thise case, getAttribute('rel') didn't return a string, but null,
or 'undefined'. None have any properties, hence the error message.

You may try using :
if (AnchorArray.hasAttribute('rel') && [...])
{
[...]
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top