title: Jquery error - Uncaught Error: Syntax error, unrecognized expression
body: <p>I'm creating a website in Wordpress, and in a Custom Post Type with a little different input interface I thought this logical:</p>
  
  <ul>
  <li>List categories (taxonomies);</li>
  <li>List posts (channels) from this categories;</li>
  <li>If you click on a post, this post is added to a text field, if click again, it's removed;</li>
  </ul>
  
  <p>The code works fine some time, but magically stops:</p>
  
  <blockquote>
    <p>load-scripts.php?c=0&amp;load[]=utils,jquery-core,jquery-migrate,moxiejs,plupload&amp;ver=4.9.8:3
    <strong>Uncaught Error: Syntax error, unrecognized expression: div#</strong>
    <strong>div.channel</strong>
        at Function.fa.error (load-scripts.php?c=0&amp;load[]=utils,jquery-core,jquery-migrate,moxiejs,plupload&amp;ver=4.9.8:3)
        at fa.tokenize (load-scripts.php?c=0&amp;load[]=utils,jquery-core,jquery-migrate,moxiejs,plupload&amp;ver=4.9.8:3)
        at fa.select (load-scripts.php?c=0&amp;load[]=utils,jquery-core,jquery-migrate,moxiejs,plupload&amp;ver=4.9.8:3)
        at Function.fa (load-scripts.php?c=0&amp;load[]=utils,jquery-core,jquery-migrate,moxiejs,plupload&amp;ver=4.9.8:3)
        at Function.a.find (load-scripts.php?c=0&amp;load[]=utils,jquery-core,jquery-migrate,moxiejs,plupload&amp;ver=4.9.8:10)
        at n.fn.init.find (load-scripts.php?c=0&amp;load[]=utils,jquery-core,jquery-migrate,moxiejs,plupload&amp;ver=4.9.8:3)
        at n.fn.init.a.fn.find (load-scripts.php?c=0&amp;load[]=utils,jquery-core,jquery-migrate,moxiejs,plupload&amp;ver=4.9.8:10)
        at a.fn.init.n.fn.init (load-scripts.php?c=0&amp;load[]=utils,jquery-core,jquery-migrate,moxiejs,plupload&amp;ver=4.9.8:3)
        at new a.fn.init (load-scripts.php?c=0&amp;load[]=utils,jquery-core,jquery-migrate,moxiejs,plupload&amp;ver=4.9.8:10)
        at n (load-scripts.php?c=0&amp;load[]=utils,jquery-core,jquery-migrate,moxiejs,plupload&amp;ver=4.9.8:3)</p>
  </blockquote>
  
  <p>My code:</p>
  
  <pre><code>        &lt;script&gt;
          // Carrega as categorias de canais
          jQuery.get(
              'http://meusite.com/wordpress/wp-json/wp/v2/canais-categorias?per_page=100&amp;orderby=name&amp;order=asc',
              function(data){
                  for(var i=0; i &lt; data.length; i++){
                      jQuery('div#channels').append(
                          '&lt;div class="row"&gt;'                                                                                     +
                              '&lt;div class="col-12"&gt;'                                                                          +
                                  '&lt;h3&gt;' + data[i].name + '&lt;/h3&gt;'                                                     +
                              '&lt;/div&gt;'                                                                                                        +
                          '&lt;/div&gt;'                                                                                                            +
                          '&lt;div class="row channel-grid" id="' +  data[i].slug + '"&gt;'     +
                          '&lt;/div&gt;'
                      );
                  }
              }, 'json'
          );
  
          // Carrega os canais
          jQuery.get(
              'http://meusite.com/wordpress/wp-json/wp/v2/canais?per_page=100&amp;orderby=title&amp;order=asc',
              function(data){
                  for(var i=0; i&lt;data.length; i++){
                      jQuery('div#' + data[i].categoria[0]).append(
                          '&lt;div class="col-3" id="' + data[i].slug + '"&gt;'         +
                              '&lt;div class="channel"&gt;'                                                     +
                                  '&lt;img src="' + data[i].channel_image + '"&gt;'         +
                                  '&lt;p&gt;' + data[i].title.rendered + '&lt;/p&gt;'                 +
                              '&lt;/div&gt;'                                                                                    +
                          '&lt;/div&gt;'
                      );
                  }
  
                  // Seleciona os caais ativos
                  var channel_grid = jQuery('input#plan_channels_grid').val();
                  var channel_grid = channel_grid.substring(0, channel_grid.length-1);
                  var channel_grid = channel_grid.split(',');
  
                  for(var i=0; i&lt;channel_grid.length; i++){
                      jQuery('div#' + channel_grid[i] + ' div.channel').addClass('active');
                  }
  
                  // Adiciona e remove um canal com um clique
                  jQuery('div.channel').click(function(){
                      var id = jQuery(this).parent().attr('id');
  
                      if(jQuery('div#' + id + ' div.channel').hasClass('active')){
                          jQuery('div#' + id + ' div.channel').removeClass('active');
  
                          var ch = jQuery('input#plan_channels_grid').val();
                          jQuery('input#plan_channels_grid').val(ch.replace((id + ','), ''));
                      }else{
                          jQuery('div#' + id + ' div.channel').addClass('active');
  
                          var ch = jQuery('input#plan_channels_grid').val();
                          jQuery('input#plan_channels_grid').val(ch + id + ',');
                      }
                  });
              }, 'json'
          );
      &lt;/script&gt;
  </code></pre>
  
  <p>Any idea?</p>