title: How to fix this error in Jquery uncaught exception: Syntax error, unrecognized expression: Syntax error, unrecognized expression: label
body: <p>So I have this function that is called in my Jquery called updateField on the blur event .. The console returns this error</p>
  
  <pre><code> uncaught exception: Syntax error, unrecognized expression: Syntax error, unrecognized expression: label
  </code></pre>
  
  <p>where is the problem ?  I can't seem to find it</p>
  
  <p>Below is the HTML code </p>
  
  <pre><code>&lt;li&gt;
      &lt;label for="element_label" class="desc"&gt;Field Label&lt;/label&gt;
      &lt;textarea class="textarea" id="element_label" onBlur="updateField()"&gt;&lt;/textarea&gt;
  &lt;/li&gt;
  &lt;li id="prop_element_name" style="display: block;"&gt;
      &lt;label for="element_names" class="desc"&gt;Field Name&lt;/label&gt;
      &lt;select id="element_names" name="element_names" onBlur="updateField()"&gt;
          &lt;?php
          if ($master_elements = query("SELECT * FROM master_elements WHERE field_type != 'scrubbed_data' ORDER BY element_label")) {
              foreach ($master_elements as $idx=&gt;$element) {
                  echo "&lt;option value=\"{$element['masterid']}\"&gt;{$element['element_label']}&lt;/option&gt;";
              }
          }
          ?&gt;
      &lt;/select&gt;
  
  
      &lt;a href="javascript:;" id="new_element_name_lnk" title="New Field Name"&gt;&lt;img src="/img/form_builder/add.gif" /&gt;&lt;/a&gt;
  
  &lt;/li&gt;
  </code></pre>
  
  <p>and Below is the updateField function being called </p>
  
  <pre><code>function updateField(option) {
      if (option) {
          input_id = $("li.current_edit").attr("id").replace(/li_/, "");
          $("li.current_edit :input#masterid_" + input_id).val( option.element_masterid );
          $("li.current_edit :input#type_" + input_id).val( option.element_type );
          $("li.current_edit :input#name_" + input_id).val( option.element_name );
          $("li.current_edit :input#validation_" + input_id).val( option.element_validation );
          $("li.current_edit :input#label_" + input_id).val( option.element_label );
          $("li.current_edit :input#guidelines_" + input_id).val( option.element_guidelines );
          $("li.current_edit :input#size_" + input_id).val( option.element_size );
          $("li.current_edit :input#options_" + input_id).val( option.element_custom_options );
          $("li.current_edit :input#format_" + input_id).val( option.element_format );
          $("li.current_edit :label#title_" + input_id).html(option.element_label);
  
          display_field_properties();
          updateField();
          return false;
      }
      else {
          input_id = $("li.current_edit").attr("id").replace(/li_/, "");
  
          inputtype = $("li.current_edit :input#type_" + input_id).val();
          $("li.current_edit :input#type_" + input_id).val(inputtype);
  
          label = $("#element_properties").find("#element_label").val();
          validation = $("#element_properties").find("#element_validation").val();
          required = $("#element_properties").find("#element_required").attr("checked");
  
          if (required) {
              $("li.current_edit :input#validation_" + input_id).val('required,' + validation);
              $("li.current_edit :label#title_" + input_id).html(label);
              $("li.current_edit :label#title_" + input_id).append('&lt;font class="required"&gt; *&lt;/font&gt;');
          }
          else {
              $("li.current_edit :input#validation_" + input_id).val(validation);
              $("li.current_edit :label#title_" + input_id).html(label);
          }
          $("li.current_edit :input#label_" + input_id).val(label);
  
  
          var name = $("#element_properties :input#element_names").val();
          $("li.current_edit :input#name_" + input_id).val(name);
          $("li.current_edit :input#masterid_" + input_id).val(name);
  
          options = $("#element_properties").find("#element_options").val();
          $("li.current_edit :input#options_" + input_id).val(options);
  
          guidelines = $("#element_properties").find("#element_guidelines").val();
          $("li.current_edit :input#guidelines_" + input_id).val(guidelines);
          $("li.current_edit div#hint_" + input_id).html(guidelines);
  
          if (inputtype == "date") {
              // str = format,input
              str = $("#date_format").val() + "|" + $("#date_input_type").val();
              $("li.current_edit :input#format_" + input_id).val( str );
              var str = '&lt;a title="Click to edit. Drag to reorder." onclick="return false;" class="hover_ready" href="#"&gt;';
              str = str + '&lt;label id="title_' + input_id + '" class="desc"&gt;' + label + '&lt;/label&gt;';
              str = str + '&lt;div&gt;';
  
              if ($("#date_input_type").val() == "select") {
                  var dd_options = '&lt;option value="1"&gt;1&lt;/option&gt;';
                  dd_options = dd_options + '&lt;option value="2"&gt;2&lt;/option&gt;';
                  dd_options = dd_options + '&lt;option value="3"&gt; .. &lt;/option&gt;';
                  dd_options = dd_options + '&lt;option value="31"&gt;31&lt;/option&gt;';
                  var mm_options = '&lt;option value="1"&gt;1&lt;/option&gt;';
                  mm_options = mm_options + '&lt;option value="2"&gt;2&lt;/option&gt;';
                  mm_options = mm_options + '&lt;option value="3"&gt; .. &lt;/option&gt;';
                  mm_options = mm_options + '&lt;option value="12"&gt;12&lt;/option&gt;';
                  var d = new Date();
                  curyear = d.getFullYear();
                  var yy_options = "";
                  for (ii=curyear; ii &lt; curyear+10; ii++) {
                      yy_options = yy_options + '&lt;option value="' + ii + '"&gt;' + ii + '&lt;/option&gt;';
                  }
                  if ($("#date_format").val() == "date") {
                      str = str + '&lt;span&gt;&lt;select id="field_' + element_idx + '_0 style="width:3em"&gt;' + mm_options + '&lt;/select&gt; / &lt;label&gt;MM&lt;/label&gt;&lt;/span&gt;';
                      str = str + '&lt;span&gt;&lt;select id="field_' + element_idx + '_1 style="width:3em"&gt;' + dd_options + '&lt;/select&gt; / &lt;label&gt;DD&lt;/label&gt;&lt;/span&gt;';
                      str = str + '&lt;span&gt;&lt;select id="field_' + element_idx + '_2 style="width:5em"&gt;' + yy_options + '&lt;/select&gt; &lt;label&gt;YYYY&lt;/label&gt;&lt;/span&gt;';
                  }
                  else if ($("#date_format").val()  == "europe_date") {
                      str = str + '&lt;span&gt;&lt;select id="field_' + element_idx + '_1 style="width:3em"&gt;' + dd_options + '&lt;/select&gt; / &lt;label&gt;DD&lt;/label&gt;&lt;/span&gt;';
                      str = str + '&lt;span&gt;&lt;select id="field_' + element_idx + '_0 style="width:3em"&gt;' + mm_options + '&lt;/select&gt; / &lt;label&gt;MM&lt;/label&gt;&lt;/span&gt;';
                      str = str + '&lt;span&gt;&lt;select id="field_' + element_idx + '_2 style="width:5em"&gt;' + yy_options + '&lt;/select&gt; &lt;label&gt;YYYY&lt;/label&gt;&lt;/span&gt;';
                  }
                  else {
                      str = str + '&lt;span&gt;&lt;select id="field_' + element_idx + '_2 style="width:5em"&gt;' + yy_options + '&lt;/select&gt; - &lt;label&gt;YYYY&lt;/label&gt;&lt;/span&gt;';
                      str = str + '&lt;span&gt;&lt;select id="field_' + element_idx + '_0 style="width:3em"&gt;' + mm_options + '&lt;/select&gt; - &lt;label&gt;MM&lt;/label&gt;&lt;/span&gt;';
                      str = str + '&lt;span&gt;&lt;select id="field_' + element_idx + '_1 style="width:3em"&gt;' + dd_options + '&lt;/select&gt; &lt;label&gt;DD&lt;/label&gt;&lt;/span&gt;';
                  }
              }
              else {
                  if ($("#date_format").val() == "date") {
                      str = str + '&lt;span&gt;&lt;input type="text" size="2" id="field_' + element_idx + '_0' + '" class="text" readonly="readonly"/&gt; / &lt;label&gt;MM&lt;/label&gt;&lt;/span&gt;';
                      str = str + '&lt;span&gt;&lt;input type="text" size="2" id="field_' + element_idx + '_1' + '" class="text" readonly="readonly"/&gt; / &lt;label&gt;DD&lt;/label&gt;&lt;/span&gt;';
                      str = str + '&lt;span&gt;&lt;input type="text" size="4" id="field_' + element_idx + '_2' + '" class="text" readonly="readonly"/&gt; &lt;label&gt;YYYY&lt;/label&gt;&lt;/span&gt;';
                  }
                  else if ($("#date_format").val()  == "europe_date") {
                      str = str + '&lt;span&gt;&lt;input type="text" size="2" id="field_' + element_idx + '_1' + '" class="text" readonly="readonly"/&gt; / &lt;label&gt;DD&lt;/label&gt;&lt;/span&gt;';
                      str = str + '&lt;span&gt;&lt;input type="text" size="2" id="field_' + element_idx + '_0' + '" class="text" readonly="readonly"/&gt; / &lt;label&gt;MM&lt;/label&gt;&lt;/span&gt;';
                      str = str + '&lt;span&gt;&lt;input type="text" size="4" id="field_' + element_idx + '_2' + '" class="text" readonly="readonly"/&gt; &lt;label&gt;YYYY&lt;/label&gt;&lt;/span&gt;';
                  }
                  else {
                      str = str + '&lt;span&gt;&lt;input type="text" size="4" id="field_' + element_idx + '_2' + '" class="text" readonly="readonly"/&gt; &lt;label&gt;YYYY&lt;/label&gt;&lt;/span&gt;';
                      str = str + '&lt;span&gt;&lt;input type="text" size="2" id="field_' + element_idx + '_0' + '" class="text" readonly="readonly"/&gt; - &lt;label&gt;MM&lt;/label&gt;&lt;/span&gt;';
                      str = str + '&lt;span&gt;&lt;input type="text" size="2" id="field_' + element_idx + '_1' + '" class="text" readonly="readonly"/&gt; - &lt;label&gt;DD&lt;/label&gt;&lt;/span&gt;';
                  }
              }
              str = str + '&lt;/div&gt;';
              str = str + '&lt;/a&gt;';
              $("li.current_edit a").replaceWith(str);
          }
          else if (inputtype == "time") {
              // str = hh(format,period),mm(format,period),ss(format,period)
              str = $("#hour_format").val() + "|" + $("#hour_period").val() + ",";
              str = str + $("#minute_format").val() + "|" + $("#minute_period").val() + ",";
              // str = str + $("#second_format").val() + "|" + $("#second_period").val();
              $("li.current_edit :input#format_" + input_id).val( str );
  
              var str = '&lt;a title="Click to edit. Drag to reorder." onclick="return false;" class="hover_ready" href="#"&gt;';
              str = str + '&lt;label id="title_' + input_id + '" class="desc"&gt;' + label + '&lt;/label&gt;';
              str = str + '&lt;div&gt;';
  
              if ($("#hour_format").val() == "select") {
                  str = str + '&lt;span&gt;&lt;select style="width: 6em;" id="field_' + input_id + '_0' + '" class="select"&gt;';
                  if ($("#hour_period").val() == 12) {
                      str = str + '&lt;option value="1AM"&gt;1 AM&lt;/option&gt;';
                      str = str + '&lt;option value="2AM"&gt;2 AM&lt;/option&gt;';
                      str = str + '&lt;option value="1PM"&gt; .. &lt;/option&gt;';
                      str = str + '&lt;option value="1PM"&gt;12 PM&lt;/option&gt;';
                  }
                  else if ($("#hour_period").val() == 24) {
                      str = str + '&lt;option value="100"&gt;1&lt;/option&gt;';
                      str = str + '&lt;option value="200"&gt;2&lt;/option&gt;';
                      str = str + '&lt;option value="2300"&gt; .. &lt;/option&gt;';
                      str = str + '&lt;option value="2400"&gt;24&lt;/option&gt;';
                  }
                  str = str + '&lt;/select&gt; : &lt;label&gt;HH&lt;/label&gt;&lt;/span&gt;';
              }
              else {
                  str = str + '&lt;span&gt;&lt;input type="text" size="2" id="field_' + input_id + '_0' + '" class="text" readonly="readonly"/&gt; : &lt;label&gt;HH&lt;/label&gt;&lt;/span&gt;';
              }
  
              if ($("#minute_format").val() == "select") {
                  str = str + '&lt;span&gt;&lt;select style="width: 4em;" id="field_' + input_id + '_1' + '" class="select"&gt;';
                  if ($("#minute_period").val() == 5) {
                      str = str + '&lt;option value="0"&gt;0&lt;/option&gt;';
                      str = str + '&lt;option value="5"&gt;5&lt;/option&gt;';
                      str = str + '&lt;option value="50"&gt; .. &lt;/option&gt;';
                      str = str + '&lt;option value="55"&gt;55&lt;/option&gt;';
                  }
                  else if ($("#minute_period").val() == 10) {
                      str = str + '&lt;option value="0"&gt;0&lt;/option&gt;';
                      str = str + '&lt;option value="10"&gt;10&lt;/option&gt;';
                      str = str + '&lt;option value="40"&gt; .. &lt;/option&gt;';
                      str = str + '&lt;option value="50"&gt;50&lt;/option&gt;';
                  }
                  else if ($("#minute_period").val() == 15) {
                      str = str + '&lt;option value="0"&gt;0&lt;/option&gt;';
                      str = str + '&lt;option value="15"&gt;15&lt;/option&gt;';
                      str = str + '&lt;option value="30"&gt;30&lt;/option&gt;';
                      str = str + '&lt;option value="45"&gt;45&lt;/option&gt;';
                  }
                  str = str + '&lt;/select&gt; &lt;label&gt;MM&lt;/label&gt;&lt;/span&gt;';
              }
              else {
                  str = str + '&lt;span&gt;&lt;input type="text" size="2" id="field_' + input_id + '_1' + '" class="text" readonly="readonly"/&gt; : &lt;label&gt;MM&lt;/label&gt;&lt;/span&gt;';
              }
              /*
              if ($("#second_format").val() == "select") {
                  str = str + '&lt;span&gt;&lt;select style="width: 4em;" id="field_' + input_id + '_2' + '" class="select"&gt;';
                  str = str + '&lt;option value="0"&gt;0&lt;/option&gt;';
                  str = str + '&lt;option value="30"&gt;30&lt;/option&gt;';
                  str = str + '&lt;/select&gt;&lt;label&gt;SS&lt;/label&gt;&lt;/span&gt;';
              }
              else {
                  str = str + '&lt;span&gt;&lt;input type="text" size="2" id="field_' + input_id + '_2' + '" class="text" readonly="readonly"/&gt;&lt;label&gt;SS&lt;/label&gt;&lt;/span&gt;';
              }
              */
              str = str + '&lt;/div&gt;';
              str = str + '&lt;/a&gt;';
              $("li.current_edit a").replaceWith(str);
          }
          else if (inputtype == "address") {
              $("li.current_edit :input#format_" + input_id).val($("#address_format").val());
              var str = "";
              if ($("#address_format").val() == "us") {
                  str = '&lt;div class="right" id="field_' + input_id + '_state"&gt;';
                  str = str + '&lt;select id="field_' + element_idx + '_3" class="select medium" &gt;';
                  str = str + '&lt;option value="AL"&gt;Alaska&lt;/option&gt;';
                  str = str + '&lt;/select&gt;&lt;label&gt;State&lt;/label&gt;';
                  str = str + '&lt;/div&gt;';
              }
              else {
                  str = '&lt;div class="right" id="field_' + input_id + '_state"&gt;';
                  str = str + '&lt;input type="text" id="field_' + element_idx + '_3" class="text medium" readonly="readonly"/&gt;&lt;label&gt;Province / Region&lt;/label&gt;';
                  str = str + '&lt;/div&gt;';
              }
              $("div#field_" + input_id + "_state").replaceWith(str);
          }
          else if (inputtype == "phone") {
              $("li.current_edit a div span").remove();
              var str = "";
              if ($("#phone_format").val() == "us_phone") {
                  $("li.current_edit :input#format_" + input_id).val("us_phone");
                  str = '&lt;span&gt;&lt;input type="text" size="3" class="text" id="field_' + element_idx + '_0' + '" readonly="readonly"/&gt; - &lt;label&gt;(###)&lt;/label&gt;&lt;/span&gt;';
                  str = str + '&lt;span&gt;&lt;input type="text" size="3" class="text" id="field_' + element_idx + '_1' + '" readonly="readonly"/&gt; - &lt;label&gt;###&lt;/label&gt;&lt;/span&gt;';
                  str = str + '&lt;span&gt;&lt;input type="text" size="4" class="text" id="field_' + element_idx + '_2' + '" readonly="readonly"/&gt;&lt;label&gt;####&lt;/label&gt;&lt;/span&gt;';
                  $("li.current_edit a div:first").append(str);
              }
              else {
                  $("li.current_edit :input#format_" + input_id).val("international");
                  str = str + '&lt;span&gt;&lt;input type="text" size="20" class="text" id="field_' + element_idx + '_0' + '" readonly="readonly"/&gt;&lt;/span&gt;';
                  $("li.current_edit a div:first").append(str);
              }
          }
          else if ( inputtype == "text" || inputtype == "textarea" || inputtype == "website" || inputtype == "email" || inputtype == "file") {
              size = $("#element_properties").find("#element_size").val();
              $("li.current_edit :input#size_" + input_id).val(size);
              $("li.current_edit :input").removeClass("small");
              $("li.current_edit :input").removeClass("medium");
              $("li.current_edit :input").removeClass("large");
              $("li.current_edit :input").addClass($("#element_size").val());
          }
          else if (inputtype == "radio" || inputtype == "checkbox" || inputtype == "select") {
              var result_str = "";
              if (inputtype == "select")  $("li.current_edit select").children().remove();
              else    $("li.current_edit span:children").children().remove();
              $("ul#element_choices li").each( function(i, ob) {
                  chkchk = "";
                  sel = "";
                  result_str = result_str + $(ob).find(":input#choice_" + i + "_name").val() + '|';
                  result_str = result_str + $(ob).find(":input#choice_" + i + "_value").val() + '|';
  
                  if ($(ob).find("img.option_default").length &gt; 0) {
                      result_str = result_str + 'default|';
                      chkchk = "checked";
                      sel = "selected";
                  }
                  else {
                      result_str = result_str + '0|';
                  }
  
                  if (inputtype == "radio") {
                      str = '&lt;input type="radio" id="field_' + input_id + '_' + i + '" name="' + name + '" class="radio" ' + chkchk + ' /&gt;&lt;label class="choice"&gt;' + $(ob).find(":input").val() + '&lt;/label&gt;';
                      $("li.current_edit span").append(str);
                  }
                  else if (inputtype == "checkbox") {
                      str = '&lt;input type="checkbox" id="field_' + input_id + '_' + i + '" name="' + name + '" class="checkbox" ' + chkchk + ' /&gt;&lt;label class="choice"&gt;' + $(ob).find(":input").val() + '&lt;/label&gt;';
                      $("li.current_edit span").append(str);
                  }
                  else if (inputtype == "select") {
                      str = '&lt;option ' + sel + ' &gt;' + $(ob).find(":input").val() + '&lt;/option&gt;';
                      $("li.current_edit :input#field_" + input_id).append(str);
                  }
              });
              $("input#options_"+input_id).val(result_str);
          }
          else if (inputtype == "states") {
              str = $("#state_format").val();
              $("li.current_edit :input#format_" + input_id).val( str );
          }
          else if (inputtype == "countries") {
              str = $("#country_format").val();
              $("li.current_edit :input#format_" + input_id).val( str );
          }
          else if (inputtype == "sectionstart" || inputtype == "sectionheader" || inputtype == "sectionend") {
              $("li.current_edit :input#masterid_" + input_id).val('0');
          }
          return false;
      }
  }
  </code></pre>