LoginSignup
2
3

More than 3 years have passed since last update.

select2でタグの文字列を取得する

Last updated at Posted at 2019-07-01

はじめに

select2でvalueではなく、text(タグの文字列)を取得する方法を調べたのでメモっておく

環境

  • Windows10
  • Edge
  • select2 4.0.6-rc.1

方法

select2('data')でタグのオブジェクト配列が取得できるため、それに対し"text"属性を取得すればよい。
例えば0番目のタグの文字列は、以下で取得できる。

$('.js-example-basic-multiple').select2('data')[0].text;

参考

How to get Selected Text from select2 when using
https://stackoverflow.com/questions/19814601/how-to-get-selected-text-from-select2-when-using-input

2
3
0

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
2
3