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?

有帮助吗?

解决方案

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

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top