LoginSignup
11
11

More than 5 years have passed since last update.

jQueryでクリックした要素のid取得

Last updated at Posted at 2018-10-26

jQueryでclickした要素のidを取り出す

メモ書きです。
苦手なので書き置きしておきます。

// 日付選択
$('.day').on('click', function() {
    var day_id = $(this).attr('id');
    console.log(day_id);
});

これをすることでカレンダーをクリックして日付を取得するコードのパーツとして使います。

attrでエラーが出たら

jQueryのバージョンの問題です。
propに書き換えてください。

// 日付選択
$('.day').on('click', function() {
    var day_id = $(this).prop('id');
    console.log(day_id);
});
11
11
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
11