要素のクラス属性の値を取得したい。
<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
});
});