Need clarification on adding JS to content item with JS injector and drupal_add_js I want to put some js on my article. Original code form http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_hide_p

is:

    &lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"&gt;&lt;/script&gt;
&lt;script&gt;
$(document).ready(function(){
    $("button").click(function(){
        $("p").hide();
    });
});
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;h2&gt;This is a heading&lt;/h2&gt;

&lt;p&gt;This is a paragraph.&lt;/p&gt;
&lt;p&gt;This is another paragraph.&lt;/p&gt;

&lt;button&gt;Click me&lt;/button&gt;

&lt;/body&gt;
&lt;/html&gt;


My article is at:   http://xuzo.com/testing/node/44

Here is what I have done


put this code in content item source code:

&lt;h2&gt;This is a heading&lt;/h2&gt;
&lt;p&gt;This is a paragraph.&lt;/p&gt;
&lt;p&gt;This is another paragraph.&lt;/p&gt;
&lt;p&gt;Click me&lt;/p&gt;

Put this in JS Injector box:

$(document).ready(function(){
$("button").click(function(){
$("p").hide();
});
});



and this for URL:

node/44



put this in my /public_html/testing/sites/all/themes/xuzo/template.php file:

drupal_add_js('https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js', 'external');

Flushed all cache
Not working!!! ;)


Additionally...for this line of code to load JS files locally:

drupal_add_js('misc/collapse.js');


Where to put the JS file? I take it misc can be any folder name? But where to put the files in relation to root? Sites/all ?
1. Like Shrish mention your code needs to be like this

(function($) {
    // your code here
    $(document).ready(function() {
        $("button").click(function() {
            $("p").hide();
        });
    });

})(jQuery);


2. your code says $("button").click(function() { but in your html there is no button:

&lt;h2&gt;This is a heading&lt;/h2&gt;
&lt;p&gt;This is a paragraph.&lt;/p&gt;
&lt;p&gt;This is another paragraph.&lt;/p&gt;
&lt;p&gt;Click me&lt;/p&gt;


So change this to:

&lt;h2&gt;This is a heading&lt;/h2&gt;
&lt;p&gt;This is a paragraph.&lt;/p&gt;
&lt;p&gt;This is another paragraph.&lt;/p&gt;
&lt;button&gt;Click me&lt;/button&gt;


3. Checkmark inline js in JS Injector