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