I'm just getting started with jQuery and I wrote a little block that uses the accordion. When I display the block in a sidebar, the accordion works just fine, but when I add the block to a panel page the javacript doesn't work.

I tried changing the style of the block to be a system block but that didn't work. The only difference I noticed between the two is that when I click on the accordion when its on the panel page, it appends an '#" to the url, which the one in the sidebar that works correctly doesn't.

Any thoughts on how to fix?

Comments

kevstav13’s picture

Here's the code that defines the block:

function accordion_block_2(){
	$name = '<div id = "block2">';
	$name .= '<h3><a href="#">' . 'People' . '</a></h3>';
	$name .= '<div>' . 'George' . '</br>';
	$name .= 'Bill' . '</br>' ;
	$name .= 'Hank' . '</div>';
	$name .= '<h3><a href="#">' . 'Animals' . '</a></h3>';
	$name .= '<div>' . 'Cow' . '</br>';
	$name .= 'Zebra' . '</br>';
	$name .= 'Horse' . '</div>';
	$name .= '</div>';
	return $name;
	}

And this is the javascript:

Drupal.behaviors.block2 = function (context) {
 $("#block2").accordion({
			collapsible: true 
          		});
};

Any idea why this would work in a standard drupal region but not in a panel?

delta’s picture

see this issue, it's maybe because of the block's caching... http://drupal.org/node/651500

where are you adding the js and do you use drupal_add_js() ?

Letharion’s picture

Status: Active » Fixed

Answered, and then no activity from OP.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.