I'm trying to add JS to content create pages using the second function from @kiamlaluno's answer
However, this is not working for me.
I created a module with his folder structure:
add_js
add_js.info
add_js.module
custom.js
add_js.info:
name = Add JS to admin pages
description = Add js to admin pages
core = 7.x
add_js.module:
<?php
function add_js_init() {
if (arg(0) == 'admin') {
$path = drupal_get_path('module', 'add_js');
drupal_add_js($path . '/custom.js');
}
}
custom.js:
jQuery(document).ready(function ($) {
$("html").addClass("hello");
});
Also tried this .module file:
<?php
function mymodule_form_alter(&$form, &$form_state, $form_id) {
switch ($form_id) {
case 'my_form':
$form['#after_build'][] = 'mymodule_after_build';
break;
}
}
function mymodule_after_build($form, &$form_state) {
$path = drupal_get_path('module', 'mymodule');
drupal_add_js ("$path/mymodule.js");
return $form;
}
Although I am pretty inexperienced still, I did remember to enable the module and flush the caches... :D