Only run javascript on certain block I have a views block that I want to modify with javascript. I can get it to load with the following in my template.php:

function THEME_preprocess_block(&amp;$variables) {  
      drupal_add_js(drupal_get_path('theme', 'THEME') . 
      '/js/script.js' ,  array('type' =&gt; 'file', 'scope' =&gt; 'footer'));
} 


However, I only want it to load when a certain block is displayed. I want to use something like:

function THEME_preprocess_block(&amp;$variables) { 
    if ($block-&gt;block_id == 'matching_id') {
      drupal_add_js(drupal_get_path('theme', 'THEME') . 
      '/js/script.js' ,  array('type' =&gt; 'file', 'scope' =&gt; 'footer'));
    }
}


If this is possible how would I go about making sure it only runs on that block?
You can just get the element like this:

$variables['elements']['#id']


And then if you would of some reason need to load the block you can do like this:

$block = entity_load('block', $variables['elements']['#id']);
$block_id = $block-&gt;id;