Adding jQuery Snippets

By peterm, 10 August, 2009

Tags

Two methods for inserting a jQuery snippet.

Method 1 - In the Views UI, navigate to Basic Settings > Header. In the Header, you can insert a jQuery snippet wrapped with <script> tags. This example sets links to open in a new window and provides advanced row striping for a table of data.

$(document).ready(function() { // override the anchor to open links in new window $('td.views-field-title a').click(function() { window.open(this.href); return false; }); // colorize the rows with zebra striping and highlighting $('#tpp-listing-2').colorize(); });

Method 2 - using drupal_add_js()