Hello,

I add javascript successfully in Drupal 7 with jQuery in Bartik / Antonelli (cf How to add Javascript in Drupal 7 with jQuery)

(creating node--article.tpl.php from node.tpl.php with

<script type="text/javascript">
    (function($) {
        $(document).ready(function(){
          $(".toggler").click(function(){
            $(this).next().slideToggle("slow");
            return false;
          }).next().hide();
        });
    })(jQuery);
</script></script>

and then creating new article with :

<style type="text/css">
  p.toggler:hover {
    color:#0071B3;
  }
</style>

<p class="toggler" style="cursor:pointer;">Show/Hide the following paragraph(s).</p>
<div>
    This paragraphe is initially hidden. Clicking on the link above will reveal (Show) all the content inside the DIV that immediately follows a "toggler" class paragraph.
</div>

)

and it works;

I tried it with Corolla 7.x-3.0-rc1 creating also node--article.tpl.php in Corolla / templates and trying to move the code at different places in the file, without success

Comments

VM’s picture

I suggest reading the comments on the link you provided which discusses using drupal behaviors rather than throwing javascript in a tpl.php file.

I'd also read through Managing JavaScript in Drupal 7