LoginSignup
18
23

More than 3 years have passed since last update.

jQueryでthis option:selectedを取得する

Last updated at Posted at 2018-09-27

jQueryのon()メソッドで、イベントの呼び出しもとセレクトボックスのthisとoption:selectedを組み合わせて使いたかったのですが、書き方がわからなかったので調べました。

以下のように書くことで実現できました。

$("option:selected", this)

$(".select_prefecture").on('change', function (e) {
    prerectureName = $("option:selected", this).text();
}
18
23
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
18
23