Data Haunting

Easy Solutions Destination


Uncaught query function not defined for Select2

Jquery Plugin Select2 throw Uncaught query function not defined for Select2 error many times , I have searched on it for a long times and also try my self and finally I could solve it . But it is desperate me when it comes again and again and waste my lots of times . So finally I decided to find it’s various reason for this error and solutions.

Reasons and Different Solutions for Uncaught query function not defined for Select2 Error

See while implementing Select2 before this jquery error Uncaught query function not defined for Select2 you can face one common jquuery error before that which shows different in all different browser. Suppose you are using google chrome and opera than it can throw uncaught typeerror undefined is not a function and suppose if you are using Mozilla firefox than you can tackle with this jquery error as typeerror $(…). is not a function and if you are using Internet Explorer(IE) than this same situation you can face as Expected identifier jquery error. So refer above link if you face any such error before Uncaught query function not defined for Select2 jquery error. Now let’s discuss solutions for this jquery error.

  1. Select2 with TextBox

  2. When we are using Select2 with TextBox this Error often throw while same error will not throw working with “select”(dropdown and combobox) elements reason is that if we see Select2 Documents, they provide default value for TextBox as a tags parameter. So one solutions is that you have to provide default value and it could be accept as a null also. As below I given example .

    One another way we we can solve using data parameter instead of tags parameter but you will see it would be seems like that it is wrapped as “select”(dropdown and combobox).

  3. Extra div added by Select2

  4. Select2 add extra div “select2-container” to wrap the select element so many times this error being thrown . We can solve this issue by adding select prefix to Select2 identifier as below.

What is your opinion ?

Here I have explained different reasons and solutions for Uncaught query function not defined for Select2 and given perfect solutions as far I have find it . I hope it will be very useful to you solve this error . If you have any query you can comment or you can mail me.

6 Responses to Uncaught query function not defined for Select2

  1. Nghia Hoang says:

    I have same problem when setup select2 ajax on input, and i add class select2 to the input, then setup select2 by input id. So just remove select2 class of textbox and problem gone 😉

    • Dilip Patel says:

      well Nghia as you commented that you added class select2 to the input and you can solve this problem that is great and we never need to specify select2 class to the html textbox. Enjoy !!

  2. Juan says:

    Solved with the second option. Thanks!!!

  3. Priya says:

    awesome.. thanks 🙂

Leave a Reply