I'm writing a custom module which outputs blocks with various deltas. Later, a jQuery code has to be attached for every generated block, aware of their id's, as in $('#mymodule-block-delta'). How is that accomplished?

1 Answer 1


You would use drupal_add_js() to pass the data from PHP to JS:

$block_ids = array('blockid1', 'blockid2');
$settings = array('myModule' => array('blockIds' => $block_ids));
drupal_add_js($settings, 'setting');

Then in JS you can pick these up like so:

var blockIds = Drupal.settings.myModule.blockIds;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.