Domanda

Code:

var articles = document.getElementsByTagName('li');
for (var i = 0; i < articles.length; i++) {
    articles[i].addEventListener('click',redirect,false);
}
function redirect(){
    alert(this.rel);
}

This code works for attribute id but not for attribute rel. Can anyone help me to get rel attribute?

È stato utile?

Soluzione

You should be accessing these attributes with element.getAttribute('attribute_name')

alert(this.getAttribute('rel'));

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top