我想获取元素的类属性的值。
<a href="http://stackoverflow.com/" id="myId" class="myClassName">Click Me</a>
this.id
,this.href
并且this.text
正在工作。
我的问题是为什么this.class
不工作?
笔记:
我不想使用:
console.log($this.attr('class'));
或者console.log($("a").prop("class"));
因为它非常慢。
$(function(){
$("a").on("click",function(){
console.log(this.id); // myId
console.log(this.href); // http://stackoverflow.com/
console.log(this.text); // Click Me
console.log($("a").prop("class")); // myClassName
});
});