If you’re adding JavaScript to your custom module it is very easy and tempting to simply add it like this: jQuery(document).ready(function($){ alert(‘hot dog flavored water’); }); Now this code works perfectly fine but what if your JavaScript needs to be executed on page load and after an AJAX request? Imagine you have a view that uses “Views Infinite Scroll” and you want add a CSS class to every result like this: jQuery(document).ready(function($){ $('.view-display-id-page .views-row').addClass('fancy-pants'); }); This will work for the results that are displayed initially but for all the results that are loaded by Infinite Scroll's AJAX call the class is not added. That’s where Drupal behaviors come in handy. The behaviors will be executed on every request including AJAX requests, so let's do the equivalent of the code above but this time using this method: Drupal.behaviors.infiniteScrollAddClass = { attach: function (context, settings) { ...