Adi
Adi

Reputation: 4022

jQuery accordion - link to open certain div

I am having a nightmare trying to get this working (and have looked at other posts but am still having an issue).

Basically I have a link like this:

/test.php#bob

on test.php I have this:

<div class="accordion">
 <h2>Customer care</h2>
 <div>
  <p>xxxxxxxxxxxxx</p>
 </div>
 <h2 id="bob">Strong leadership from start to finish</h2>
 <div>
  <p>fffffffffff</p>
 </div>
 <h2>Certainty of delivery, no matter how complex or difficult</h2>
 <div>
  <p>dddddddddd</p>
 </div>
</div>

And in jQuery I have this:

$(".accordion").accordion({
 autoHeight: false,
 collapsible: true,
 navigation: true,
 active: 'none'
});

But I still cant get the #bob panel to open via the link.

Any ideas? Im pulling my hair out.

A.

Upvotes: 0

Views: 2396

Answers (1)

Nick Craver
Nick Craver

Reputation: 630409

You can do it like this:

$(".accordion").accordion({
 autoHeight: false,
 collapsible: true,
 navigation: true,
 active: 'none'
});
if(location.hash) $(location.hash).click();

This would perform a click on the <h2> (by using the hash, which includes the # as an #id selector), invoking the standard accordion behavior.

Upvotes: 2

Related Questions