You should be accessing these attributes with element.getAttribute('attribute_name')
alert(this.getAttribute('rel'));
質問
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'));