Event bindinding to a control with jQuery & turbolinks
// evolution.js function hideMessage() { $('#message').addClass('invisible'); }; var ready; ready = function() { $('#emergency_evolution').on('click', function(event) { hideMessage(); }); }; $(document).ready(ready); $(document).on('page:load', ready);
# evolution.html.erb <% content_for :js do %> <%= javascript_include_tag 'evolution', 'data-turbolinks-track' => true %> <script> hideMessage(); </script> <% end %> ...
# application.html - head ... <%= yield :js if content_for?(:js) %> ...
# evolution.html.erb <%= f.text_area :evolution, class: "form-control" %> ---> id="emergency_evolution
MINI JQUERY
window.$ = function(s) { var c = { '#': 'ById', '.': 'sByClassName', '@': 'sByName', '=': 'sByTagName'}[s[0]]; return document[c?'getElement'+c:'querySelectorAll'](s.slice(1)) };
con estos 2xx bytes y sin necesidad de jQuery, puedes hacer:
$('#cabecera") o $('.cabecera)