Search code examples
javascriptjqueryhtmldrupaldrupal-7

How to merge custom code with drupal


I am trying to add jquery slider code to my drupal site, in one of the block in my site.

But i am not able to add my code to drupal site & get it working.

How can i add the custom code to drupal site.

How can i solve this?

Code:

<script src="js/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $(".featured1").slideUp(7000);
});
</script>

<div class="featured1"><img src="images/2.png"></div>

Solution

    1. Create js file in your theme_folder/js, e.g, scripts.js, put your code into that file, open .info file of theme and add scripts[]=js/scripts.js OR
    2. Create a js file as I wrote above and open template.php of your theme and put

      drupal_add_js(drupal_get_path('theme', 'YOUR_THEME_NAME') . '/js/scripts.js', array('type' => 'file', 'group' => JS_THEME));
      

      in YOUR_THEME_preprocess_page().