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>
theme_folder/js
, eg, scripts.js, put your code into that file, open .info file of theme and add scripts[]=js/scripts.js
OR 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()
.
Avoid adding JS in your blocks. Use a file in your theme (like /sites/all/themes/your_theme/js/my_scripts.js). Many Drupal themes include a script.js, using Drupal JS behaviors (like Zen). You can also add your own custom JS file modifying the your_theme.info file (you'll find examples all around).
If you really want to add JS in a block, you may run into JS aliases problem, replacing "$" by "jQuery" can help. But, really, don't do that, it's gonna be a mess to maintain :)....
Good luck
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.