views:

37

answers:

2

In the header of my website I have 3 random previews.

<ul id="dm_list">
<li><div id="sinistra"><script>boxsinistro_ita();</script></div></li>
<li><div id="centro"><script>boxcentrale_ita();</script></div></li>
<li><div id="destra"><script>boxdestro_ita();</script></div></li>
</ul>

Clicking one of the previews, you go in a webpage with "JQuery Accordion" Menu. For example:

  • menu1
  • menu2
  • menu3

How can I open the "toggle" section that I click in the header?

A: 

Use the activate method for the Accordion. Assuming they are in the same order as the list items in your header, you can use the indexed version.

$('#dm_list > li a').click( function() {
    var index = $('#dm_list > li a').index(this);
    $('#menu').accordion('activate',index);
    return false;
});

EDIT:

Turns out it's easier than I thought if you want to specify the section to open on a different page. The accordion already handles this with the navigation option. Just make sure the hash in the url matches the id of the accordion section you want. Note this code goes on the page with the accordion.

 <script type="text/javascript">
     $(function() {
          $('#menu').accordion( { navigation: true } );
     });
 </script>
tvanfosson
How can I insert the activate method here: document.write('<a class="swith" rel="'+fotogrande[ry]+'" href="'+link[ry]+'"><img src="'+fotopiccola[ry]+'" border=0><b>'+titolo[ry]+'</b><br>'+descrizione[ry]+'</a>')
Marco
@Marco -- while the name of the accordion I used was fictitious, the code above, placed in a script container, should suffice if the accordion is on the same page (though I'd probably change it to go off the link and return false to prevent the link action - I'll update this). If the accordion is on a different page, then you'd have to resort to figuring out on document load which section is needed from the page url and put the inner code on that page. This case would probably use the version that takes a selector instead of the index number.
tvanfosson
Yes the accordin is in another page and I would like something the anchors, is it possible?<a name="name"><a href="pageName.html/#name">
Marco
@Marco - using the hash that corresponds to the accordion id will work. I'll update with an example for that case.
tvanfosson
@Marco -- you just need to use the navigation option on the accordion to make this work. I've updated.
tvanfosson
@tvanfosson: I tryied also this solution but it not run.
Marco
@Marco - you need to change the selector to be your accordion's name. Also make sure that you have included all the bits of jQuery on the page.
tvanfosson
@tvanfosson: yes, i done it, but not run.
Marco
@Marco -- I said "name", but I assumed you knew I meant "id". The hash selector selects based on id, not name. If it's still not working, then you might need to post the code + html of the page with the accordion.
tvanfosson
@tvanfosson: code posted
Marco
@Marco - you really should have edited your question and added it there instead of in an answer. Also, there's not enough code there to go on. Where is the jQuery for the accordion, what is the container that you are are using?
tvanfosson
The container for Accordion is the code below "HTML with Accordion classes:". It run good.
Marco
I found this, but it not run too, can you help me?http://forum.jquery.com/topic/accordion-open-a-specific-tab-with-link-from-another-page
Marco
@tvanfosson: done. Thank you very much! =)
Marco
A: 

HTML with the menu:

<ul id="dm_list">
<li><div id="sinistra"><script>boxsinistro_ita();</script></div></li>
<li><div id="centro"><script>boxcentrale_ita();</script></div></li>
<li><div id="destra"><script>boxdestro_ita();</script></div></li>
</ul>

boxsinistro_ita() = box_centrale_ita() = boxdestro_ita() =

document.write('<a class="swith" rel="'+fotogrande[ry]+'" href='+'"'+link[ry]+'"'+'><img src="'+fotopiccola[ry]+'" border=0><b>'+titolo[ry]+'</b><br>'+descrizione[ry]+'</a>');

HTML with Accordion classes:

<div class="title">TITLE1</div>
<div class="title">TITLE2</div>
<div class="content">CONTENT1</div>
<div class="content">CONTENT2</div>
Marco