Why script doesn't work

Why script doesn't work

Hello dear jquery people. I'm new in jquery

I have some code:


My index html:

  1. <html>

  2. <head>

  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" >


  4. <link rel="stylesheet" type="text/css" href="test.css"/>

  5. <script type="text/javascript" src="jquery-1.10.1.min.js"></script>


  6. <script type="text/javascript">

  7. $(document).ready(function() {
  8. (function ($) {
  9.    //тут превращаем select в input    
  10.    var id = "test",
  11.        $id = $('#' + id),
  12.        choices = $id.find('option').map(function (n, e) {
  13.            var $e = $(e);
  14.            return {
  15.                id: $e.val(),
  16.                text: $e.text()
  17.            };
  18.        }),
  19.        width = $id.width(),
  20.        realClass = $id.get(0).className,
  21.        realId = $id.get(0).id,

  22.        $input = $('<input>',{width: width});
  23.    $id.after($input);
  24.    $id.hide();
  25.    $id.find('option').remove();
  26.    //превратили

  27.    $input.select2({
  28.        query: function (query) {
  29.            var data = {}, i;
  30.            data.results = [];

  31.            // подтставим то что искали

  32.            if (query.term !== "") {
  33.                data.results.push({
  34.                    id: query.term,
  35.                    text: query.term
  36.                });
  37.            }

  38.            // добавим остальное

  39.            for (i = 0; i < choices.length; i++) {
  40.                if (choices[i].text.match(query.term) || choices[i].id.match(query.term)) data.results.push(choices[i]);
  41.            }

  42.            query.callback(data);
  43.        }
  44.    }).on('change',function()
  45.          {   
  46.              var value=$input.val();
  47.              $id.empty();
  48.              $id.append($('<option>').val(value))
  49.              $id.val(value).trigger('change');             
  50.          }
  51.         );
  52. })(jQuery);
  53. });

  54. </script>

  55. </head>

  56. <body>

  57. <select id='test' class="testclass">
  58.     <option value="1">test1</option>
  59.     <option value="2">test2</option>
  60.     <option value="3">test3</option>
  61.     <option value="4">test4</option>
  62. </select>

  63. </body>

  64. </html>

my css:

  1. #test {
  2.     width: 300px;
  3. }

Why it doesn't work?? Can not understand?