title: Jquery code won't run loaded from footer, but run from console
body: <p>I'm trying to get a value and pass it to a hidden input in order to send form data via <code>$_POST</code>. I have a dropdown button and the following code in order to update the value when a user select an option:</p>
  
  <pre><code>jQuery(document).ready(function($) {
      var espSeleccionada = $('button[data-id="select-especialidad"]');
      espSeleccionada.on("click", function() {
          var x = $(this).text();
          $('#boton-prueba').text(x);
      });
  });
  </code></pre>
  
  <p>The code is supposed to pass the value from one button to another, as shown in here the example, but, when I load the code from WordPress header/footer/theme nothing happens. Instead, when I write it on the console it works fine. There are no JS errors in console.</p>
  
  <p>Please note that I'm using <code>.text()</code> to test if the code works, but it would have <code>.val()</code> before going live.</p>
  
  <p>This is the button HTML:</p>
  
  <pre><code>&lt;button type="button" class="btn dropdown-toggle btn-default" data-toggle="dropdown" data-id="select-especialidad" title="Hacienda" aria-expanded="false"&gt;&lt;span class="filter-option pull-left"&gt;Hacienda&lt;/span&gt;&lt;/button&gt;
  </code></pre>
  
  <p>Here is an example: <a href="https://fiddle.jshell.net/t9mvoxj5/" rel="nofollow">https://fiddle.jshell.net/t9mvoxj5/</a></p>
  
  <p>EDIT TO INCLUDE THE FULL CODE:</p>
  
  <pre><code>( function( $ ) {
      var num_cols = 3,
      container = $('#menu-preparadores-de-oposiciones-en'),
      listItem = 'li',
      listClass = 'sub-list';
      container.each(function() {
          var items_per_col = new Array(),
          items = $(this).find(listItem),
          min_items_per_col = Math.floor(items.length / num_cols),
          difference = items.length - (min_items_per_col * num_cols);
          for (var i = 0; i &lt; num_cols; i++) {
              if (i &lt; difference) {
                  items_per_col[i] = min_items_per_col + 1;
              } else {
                  items_per_col[i] = min_items_per_col;
              }
          }
          for (var i = 0; i &lt; num_cols; i++) {
              $(this).append($('&lt;ul &gt;&lt;/ul&gt;').addClass(listClass));
              for (var j = 0; j &lt; items_per_col[i]; j++) {
                  var pointer = 0;
                  for (var k = 0; k &lt; i; k++) {
                      pointer += items_per_col[k];
                  }
                  $(this).find('.' + listClass).last().append(items[j + pointer]);
              }
          }
      });
  
      if ($("body").hasClass("page-id-64")) {
        $('.tab-content').addClass('col-sm-9');
        $('#custom-tabs-0').tabCollapse();
      }
  
  } ) ( jQuery );
  
  jQuery(document).ready(function($) { 
      var espSeleccionada = $('button[data-id="select-especialidad"]');
      espSeleccionada.on("click", function() {
          var x = $(this).text();
          $('#boton-prueba').text(x);
      });
  });
  </code></pre>