custom js in bootstrap sub-theme is loaded, works in console, but doesn't actually work in browser I have a bootstrap subtheme with scripts[] = script.js in the .info file.  When I go to the site and view html source of the page I can see that drupal is including the file &lt;script src="http://site/path/to/subtheme/script.js?ox2bif"&gt;&lt;/script&gt; and if I click on that link and I see the expected contents of the file:

jQuery(document).ready(function(){
  jQuery('p').click(function(){alert("hello");});
});


The js works, the  links to the actual file.  What else is there?

If I paste jQuery('p').click(function(){alert("hello");}); into my browser's js console then, obviously, clicking any paragraph opens an alert popup window.  But what am I missing that it's not working in the Drupal theme?



Additional info:


Drupal 7
Bootstrap base theme 7.x-3.15
Using Bootstrap CDN (not the SASS or LESS starterkits) with version 3.3.7
Using jQuery version 2.1


switching to jQuery 2.2 or 3.1 doesn't not help





Currently doing:

function winprevent_custom_page_build(&amp;$page) {                                                  
  $themescript = drupal_get_path('theme', 'winprevent') . '/script.js';
  drupal_add_js($themescript, array('group' =&gt; JS_LIBRARY, 'weight' =&gt; -10));


...in a custom module to load the script from the theme.  Notice the 'group' =&gt; JS_LIBRARY; this was necessary to get the file to load before admin_menu module's js.  Disabling admin_menu stops it from breaking.  The presence of admin_menu.js also breaks the animation of Bootstrap's collapse feature.

So scripts[] = script.js actually does work in the theme but only for anonymous users, it breaks for the authenticated users (who all have access to the admin menu).
what am I missing that it's not working in the Drupal theme


You're not using proper jQuery Drupal syntax

(function ($) {

     //code starts
     $('p').click(function(){
        alert("hello");
     });
    //code ends

}(jQuery)); 


See Working with JavaScript and jQuery for an in-depth explanation.