This is the right & simple way to include any JS file in Drupal 7.
- Create a folder named i.e.
js
, inside your module folder. - Inside that folder place
(modulename).js
file.
Note: Drupal JS code has a specific format as follows:
(function ($) {
$(document).ready(function(){
alert("Hello world!"); //here we can add our JS code
});
})(jQuery);
Open
(modulename).info
file & add:scripts[] = js/(modulename).js
Clear Cache & Run.