Search code examples
javascriptjqueryjquery-select2

How to change placeholder in select2?


How do I change the data placeholder with select2?

So far I've tried this.

$("#city").select2({placeholder:"foo"});

And this...

$("#city").attr("data-placeholder","bar");

But neither works.


Solution

  • I found that if I just set the attr e.g. $("#city").attr('data-placeholder', 'bar'), there is no effect. However, if I set the attr and then call $("#city").select2() with no arguments, then the placeholder updates.

    e.g.

    $("#city").attr("data-placeholder","bar");
    $("#city").select2();