jQuery

jQuery id 取得方法

2014年3月28日

jQuery でオブジェクトの id を取得するためには attr メソッドを使います。

例えばこんな感じ・・・

$(document).ready(function() { alert($(this).attr('id')); });

あまり登場機会は多くないかもしれませんが、動的にエレメントを取得したときは使うかもしれません。

-jQuery