diff --git a/webform_conditional/webform_conditional.module b/webform_conditional/webform_conditional.module
index 562a4da..9f5546f 100644
--- a/webform_conditional/webform_conditional.module
+++ b/webform_conditional/webform_conditional.module
@@ -135,8 +135,7 @@ function webform_conditional_form_alter(&$form, $form_state, $form_id) {
         }
       }
     }
-    //can't add javascript in this function or it will not be added if the form is built from cache.  Need to run "after_build" function
-    $form['#after_build'][] = 'webform_conditional_add_js';
+
     $js_settings = array(
       // Rewrite previous settings if the form is being rebuilt.
       'webform_conditional_' . $form_id => array(
@@ -145,8 +144,15 @@ function webform_conditional_form_alter(&$form, $form_state, $form_id) {
         'showSpeed' => NULL, //'fast',
       )
     );
-    //store JavaScript variable for the webform_conditional_add_js function
-    $form['#webform_conditional_js'] = $js_settings;
+
+    $form['#attached']['js'][] = array(
+      'type' => 'file',
+      'data' => drupal_get_path('module', 'webform_conditional') . '/webform_conditional.js',
+    );
+    $form['#attached']['js'][] = array(
+      'data' => $js_settings,
+      'type' => 'setting',
+    );
   }
 }
