Pregunta

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?

¿Fue útil?

Solución

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

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top